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'? –