[Tutor] error when using using subprocess.popen in Python wrapper script

Rogelio scubacuda at gmail.com
Mon May 7 03:52:05 CEST 2012


I am new to Python and am trying to figure out how to execute Linux
commands via a Python wrapper.

This works

**********************
#this works okay
import subprocess

uname = "uname"
uname_arg = "-a"

subprocess.call([uname,uname_arg])
**********************

But this doesn't.

***********************
#this doesn't work
import subprocess

#perl prog works in real life
perl_prog = "perl perlprog.pl"
perl_prog_h ="-h"

#this is where it breaks
subprocess.call([perl_prog, perl_prog_h])

************************

I get the following error when I run the program

python errorCheck.py

Linux mybox.domain.com 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:13
EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Traceback (most recent call last):
  File "errorCheck.py", line 16, in ?
    subprocess.call([perl_prog, perl_prog_h])
  File "/usr/lib64/python2.4/subprocess.py", line 419, in call
    return Popen(*args, **kwargs).wait()
  File "/usr/lib64/python2.4/subprocess.py", line 550, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.4/subprocess.py", line 996, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory


any suggestions?


More information about the Tutor mailing list