嘿,我有这个PHP代码来调用python文件但是当我在浏览器上运行php代码时它会出错...:

时间:2013-07-02 11:23:47

标签: php python

php代码:

<?php
   exec("C:/Python27/python qwer.py 2>&1", $output);
   print_r($output);
?>

Python代码:

f = open('myfile.txt','w')
f.write('hi there\n')

错误:

Array ( [0] => C:/Python27/python: can't open file 'qwer.py': [Errno 2] No such file or directory )

1 个答案:

答案 0 :(得分:1)

为qwer.py提供完整路径,如下所示

<?php
   exec("C:/Python27/python c:/scripts/qwer.py 2>&1", $output);
   print_r($output);
?>