2015-04-17 95 views
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"; 
?>% 
+0

'exec_path'在两种情况下都是一样的吧?我想知道这是否是一个许可问题。 –

+0

但我仍然能够从命令行执行该文件,如php /tmp/regraphd_testing_dir_A5wdrS/queries/tmp0AKqI6.php, 但是,路径是相同的 – riri

+0

不应该PHP文件以'<?开头。 php'? –

回答

0

我固定我的问题。之前我写过文件内容,并且忘记flush()它,所以当exec调用发生时文件是空的。

相关问题