这是我的计划 导入子流程
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"
因此,当我从命令行运行它时效果很好,例如follow-&gt;
[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-&gt;
[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
答案 0 :(得分:1)
消息sorry, you must have a tty to run sudo
是关键。首先,让你的apache运行sudo至少可以说是危险的,但如果你真的想要这样做......有办法,编辑/etc/sudoers
(visudo
)并找到{{ 1}} part(Defaults requiretty
)。
注意:永远不要让apache使用sudo运行任何东西,准确指出它需要做什么,仅此而已!
BTW:如果你启用了SELinux或其他LSM模块,它可能仍然无效。