在调用另一个脚本时遇到问题,顺便说一下,当我调用python main.py(然后调用test3.py)时它从控制台运行正常但是当我通过webserver执行它时,它给出了下面的错误,它是隐蔽
我不能称之为(test3只是一个打印......)
#proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
但这很好用
proc = subprocess.Popen(['ls', '-la'], stdout=subprocess.PIPE)
错误登录FreeBSD上的/var/log/httpd-error.log
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] Traceback (most recent call last):
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/www/apache22/data/main2.py", line 22, in <module>
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 679, in __init__
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] errread, errwrite)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 1228, in _execute_child
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] raise child_exception
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] OSError
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] :
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] [Errno 2] No such file or directory
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File does not exist: /usr/local/www/apache22/data/favicon.ico
答案 0 :(得分:2)
python
可执行文件不在网络服务器executable PATH中。 Web服务器也可能使用chroot或类似技术进行保护,因此无法访问python安装。
尝试指定python可执行文件的完整路径(可以使用which
命令以交互方式找到它),如下所示:
proc = subprocess.Popen(['/usr/bin/python', 'test3.py'], stdout=subprocess.PIPE)
答案 1 :(得分:0)
您可以直接将test3代码导入项目而不是通过操作系统调用吗?
你的相对路径都是正确的吗?听起来你可能正在从错误的目录运行某些东西或者在远程机器上的目录中缺少一些所需的文件。