I too am trying to write a similar program that I would be using later to integrate with CGI, so that the work that is done by the script through a command prompt can be done directly through the browser, just by the click of a button (or similar action).
I have some sort of bug in my initial script itself, which gives me the following error. The Script and the error are as follows.
SCRIPT-->
#!/usr/bin/python
import cgi, string, os, sys, cgitb, commands, subprocess
import posixpath, macpath
comd = [\
"tar -xf x.tar.gz", \
"cd demo", \
"cp README ../", \
]
outFile = os.path.join(os.curdir, "output.log")
outptr = file(outFile, "w")
errFile = os.path.join(os.curdir, "error.log")
errptr = file(errFile, "w")
retval = subprocess.call(comd, 0, None, None, outptr, errptr)
errptr.close()
outptr.close()
if not retval == 0:
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(errData))
ERROR-->
Traceback (most recent call last):
File "process.py", line 18, in
retval = subprocess.call(comd, 0, None, None, outptr, errptr)
File "/usr/lib/python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I would be thankful to you all for any suggestions in this regard and also for some precautions that I may require to get this working via the browser too.
Regards.