我有一个python脚本writetest.py,包含以下内容:
print "mark1"
with open("/testfile.txt", "a") as myfile:
myfile.write("Hello World")
print "mark2"
当我在shell中调用scrip时,它会工作并在testfile.txt中添加“Hello World”。当我使用php exec命令调用它时,它不会写:
exec('python writetest.py', $output, $return_var);
print_r($output);
print_r($return_var);
打印内容:
Array ( [0] => mark1 )
1
我的python脚本运行,但在打开代码时停止
我认为你的代码中有报价问题
一旦你修好了,再试一次。 如果还是不行,我建议
见:http://php.net/manual/en/function.exec.php
然后打印输出并通过print\u r返回\u var,以便调试
正如艾恩伯指出的,这是一个权限问题。我给了web服务器用户写访问权限,它成功了
相关问题 更多 >
编程相关推荐