Is subprocess.Popen completely broken?


S

Skip Montanaro

I am trying to replace os.system calls with subprocess.Popen. This simple
example fails miserably:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/titan/skipm/local/lib/python2.5/subprocess.py", line 594, in __init__
errread, errwrite)
File "/home/titan/skipm/local/lib/python2.5/subprocess.py", line 1091, in
_execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

I also tried explicitly referencing /usr/bin/ls. Same result. What gives?
I see this behavior in both Python 2.4 and 2.5 on Solaris 10 and with
2.6alpha on Mac OS X.

Frustrated in Chicago...

Skip
 
Ad

Advertisements

J

Jeffrey Froman

Skip said:
I am trying to replace os.system calls with subprocess.Popen.  This simple
example fails miserably:

Popen expects a list of program arguments. When passed a single string
instead of a list, as in your example, it assumes that the string is the
command, and looks for an executable named "ls /tmp", which of course does
not exist.

Split your command into a list of separate parameters, with the executable
as the first parameter, and it will work:
subprocess.Popen(['ls', '/tmp'])
(ls output here)


Jeffrey
 
Ad

Advertisements

M

Martin Blume

Your lack of faith in Python is somewhat
disturbing ...
I have consistently made the experience that when
I was about to ask "is X completely broken", the
error was on my side.

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top