【发布时间】:2015-04-17 05:02:14
【问题描述】:
我有一个从 python 调用 PHP 的程序,带有 popen,但我没有从我的调用中得到任何 stdout 或 stderr。
有问题的行是:
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,但是是的,路径是一样的
-
PHP文件不应该以
<?php开头吗? -
另外,最后的
%是干什么用的? -
哦,那只是表示那里没有换行符的shell