Here's my program import subprocess

print "Content-type:text/html\r\n\r\n"
print "File starting to execute"
print "<br>"
proc = subprocess.Popen(["sudo", "python", ""], stdout=subprocess.PIPE)
output =
print "output is %s" %output

print "<br>"
print "File Executed Awesomely"

Then when I run it in the command line it really works great, like follows->

[root@localhost html]# python

File starting to execute

output is .
Sent 1 packets.

File Executed Awesomely
[root@localhost html]# 

that's perfect the ". Sent 1 packets." is exactly what I would like. However when I run it in the web page, the web page merely has

File starting to execute
output is
File Executed Awesomely

and so i initially thought it was because I had been doing a problem getting the output however i took in around the port with wireshark (my other program it calls send a packet) also it appears like no packets turns up through the web page call, however it does after i refer to it as around the command line (exactly the same way). Searching inside my 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

any suggestions how I'm able to repair it so my apache cgi-bin script runs exactly the same way because the command line?

EDIT: searching in the log following a couple of calls it will this frequently

[Wed Jan 18 18:22:37 2012] [error] [client] :
[Wed Jan 18 18:22:37 2012] [error] [client] sorry, you must have a tty to run sudo 

The content sorry, you must have a tty to run sudo is paramount. To begin with, letting your apache run sudo is harmful as you would expect, but when you actually actually want to get it done... there is a way, edit /etc/sudoers (visudo) and locate the Defaults requiretty part (man sudoers).

NB: Never let apache run anything using sudo, specify what it really must do and absolutely nothing more!

BTW: It might still not work for those who have SELinux enabled or any other LSM module.