Re: Subprocess module in Python CGI
Hello Kenneth, Thank you for your suggestion. This was helpful to remove a sort of redundancy in my program but removal of '\' still does not solve my problem as the Error displayed remains exactly the same. Any other suggestions? Once again thank you so much for your valuable time. Regards. On Dec 23 2008, 1:59 pm, Kenneth Gonsalveswrote: > On Monday 22 Dec 2008 4:21:31 pm Anurag wrote: > > > comd = [\ > > "tar -xf x.tar.gz", \ > > nothing to do with python: > [law...@localhost programs]$ tar -xf x.tar.gz > tar: x.tar.gz: Cannot open: No such file or directory > tar: Error is not recoverable: exiting now > > btw, there is no need to put '\' when putting a list in more than one line. In > general, in python, you can put anything within (), [] or {} on more than one > line without any escaping. > > -- > regards > KGhttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Subprocess module in Python CGI
On Monday 22 Dec 2008 4:21:31 pm Anurag wrote: > comd = [\ > "tar -xf x.tar.gz", \ nothing to do with python: [law...@localhost programs]$ tar -xf x.tar.gz tar: x.tar.gz: Cannot open: No such file or directory tar: Error is not recoverable: exiting now btw, there is no need to put '\' when putting a list in more than one line. In general, in python, you can put anything within (), [] or {} on more than one line without any escaping. -- regards KG http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Subprocess module in Python CGI
I have also missed out a last line at the end of the Traceback ... this may be important in fishing out the error. The last line is: OSError: [Errno 2] No such file or directory Looking forward to some kind of suggestions. Thanking you all once again and with Regards. On Dec 22, 11:51 am, Anuragwrote: > Hello, > > I have started using python recently and would like to call a short > python script via > browser using a CGI script, but initially I am trying to call the same > python script directly through python command line. The script intends > to > perform a few command line in a pipe and I have written the script (a > short > one) as follows. I would later also like to import this application to > Django. > > #!/usr/bin/python > > import cgi, string, os, sys, cgitb, commands, subprocess > import posixpath, macpath > #file = "x.tar.gz" > #comd = "tar -xf %s" % (file) > #os.system(comd) > #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../') > 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)) > > but after trying to execute this independently, I get the following > error > which I am unable to interpret : > > 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 > > Could someone suggest where am I going wrong and if corrected, what is > the > probability of this script being compatible with being called through > the > browser. Thanking you people in advance. > > Regards. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Subprocess module in Python CGI
Hello, I have started using python recently and would like to call a short python script via browser using a CGI script, but initially I am trying to call the same python script directly through python command line. The script intends to perform a few command line in a pipe and I have written the script (a short one) as follows. I would later also like to import this application to Django. #!/usr/bin/python import cgi, string, os, sys, cgitb, commands, subprocess import posixpath, macpath #file = "x.tar.gz" #comd = "tar -xf %s" % (file) #os.system(comd) #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../') 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)) but after trying to execute this independently, I get the following error which I am unable to interpret : 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 Could someone suggest where am I going wrong and if corrected, what is the probability of this script being compatible with being called through the browser. Thanking you people in advance. Regards. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---