这是我的程序导入子流程
print "Content-type:text/html\r\n\r\n"
print "File starting to execute"
print "<br>"
proc = subprocess.Popen(["sudo", "python", "test3.py"], stdout=subprocess.PIPE)
output = proc.stdout.read()
print "output is %s" %output
print "<br>"
print "File Executed Awesomely"
因此,当我从命令行运行它时,它运行良好,如下所示->
[root@localhost html]# python test2.py
Content-type:text/html
File starting to execute
<br>
output is .
Sent 1 packets.
<br>
File Executed Awesomely
[root@localhost html]#
那就是完美的“。发送了 1 个数据包”。是我想要的。但是当我从网页运行它时,网页只有
File starting to execute
output is
File Executed Awesomely
所以我最初认为这是因为我在抓取输出时做错了,但我用wireshark在端口上监听(它调用的我的另一个程序发送一个数据包)并且看起来没有数据包通过网页调用显示,但它确实在我在命令行上调用它(以相同的方式)。查看我的 apache error_log->
[Wed Jan 18 18:15:11 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jan 18 18:15:11 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Jan 18 18:15:11 2012] [notice] Digest: done
[Wed Jan 18 18:15:11 2012] [warn] ./mod_dnssd.c: No services found to register
[Wed Jan 18 18:15:11 2012] [notice] Apache/2.2.17 (Unix) DAV/2 configured -- resuming normal operations
关于如何修复它的任何建议,以便我的 apache cgi-bin 脚本以与命令行相同的方式运行?
编辑:在几次调用后查看日志,它会重复执行此操作
[Wed Jan 18 18:22:37 2012] [error] [client 10.117.153.89] :
[Wed Jan 18 18:22:37 2012] [error] [client 10.117.153.89] sorry, you must have a tty to run sudo