Hello all. I have a cgi python program which runs an os.system command and this command is printing output and causing havoc. How do I get python to run the os.system command and have that command print to the webpage it is being run on?
A:
Do you have to use os.system? I would use
stdout, stderr = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr.PIPE).communicate()
TooAngel
2010-06-21 17:21:26
Follow up question, is it possible to have it printing to the webpage in realtime? The python program runs a script which runs an extended process which produces output over a 2 minute or so period of time.
EricR
2010-06-21 17:39:28
In the end Yes :-) But (everytime there is a but), on web application you have a special amount of time in which the request can produce a response and this is limited. So if you want to enable the page visitor to execute long running processes, you should execute the process in a worker thread. Put the output to a database/file/orWhatYouLike and update the web page with e.g. ajax in an asynchronous way.
TooAngel
2010-06-21 17:47:11