1
我有一个程序从python调用PHP,使用popen,并且我没有从我的调用中获取任何stdout或stderr。我为什么不能从PHP获得输出,使用Python Popen
有问题的线路有:
task = subprocess.Popen(
['/usr/bin/php', exec_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env
)
stdout_str, stderr_str = task.communicate()
task_result = task.returncode
当我更换LS PHP的路径,它的工作原理:
task = subprocess.Popen(
['/bin/ls', exec_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env
)
stdout_str, stderr_str = task.communicate()
task_result = task.returncode
# Works as expected
当我从shell运行PHP命令,但它产生的输出。
作为参考,PHP文件是:
<?
echo "YAY";
?>%
'exec_path'在两种情况下都是一样的吧?我想知道这是否是一个许可问题。 –
但我仍然能够从命令行执行该文件,如php /tmp/regraphd_testing_dir_A5wdrS/queries/tmp0AKqI6.php, 但是,路径是相同的 – riri
不应该PHP文件以'<?开头。 php'? –