これが私のプログラムインポートサブプロセスです
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パケットを送信しました。」私が欲しいものです。しかし、私がWebページから実行すると、Webページには
File starting to execute
output is
File Executed Awesomely
もともと、これは出力を取得するのに何か間違ったことをしているためだと思っていましたが、wiresharkでポートをリッスンしました(他のプログラムはパケットを送信します)。Webページの呼び出しではパケットが表示されないようですが、コマンドラインで呼び出します(同じ方法)。私のapacheerror_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