[Tutor] error when using using subprocess.popen in Python wrapper script
Martin A. Brown
martin at linux-ip.net
Mon May 7 05:23:40 CEST 2012
Hello,
: perl_prog = "perl perlprog.pl"
: perl_prog_h ="-h"
: #this is where it breaks
: subprocess.call([perl_prog, perl_prog_h])
This is asking your Linux to search your $PATH and execute a program
called:
'perl perlprog.pl'
Rather than to execute a program called 'perl' and pass as the first
argument 'perlprog.pl'.
perl_bin = 'perl'
perl_prog = '/path/to/perlprog.pl'
perl_prog_h = '-h'
subprocess.call([perl_bin, perl_prog, perl_prog_h])
Or, if I were in your shoes, I would do something a bit more like
this:
cmd = [ '/usr/bin/perl', '/path/to/perlprog.pl', '-h' ]
subprocess.call(cmd)
Probably the most interesting thing here for you to note in the long
run is to learn what 'magically' happens in the shell when you run a
command. Since you are using Linux, you may find strace useful
to see what Python is passing to your system for execution:
strace -e process python /path/to/your/python/script.py
Enjoy,
-Martin
--
Martin A. Brown
http://linux-ip.net/
More information about the Tutor
mailing list