Is subprocess.Popen completely broken?
Jeffrey Froman
jeffrey at fro.man
Thu Mar 27 11:04:43 EDT 2008
Skip Montanaro wrote:
> I am trying to replace os.system calls with subprocess.Popen. This simple
> example fails miserably:
>
>>>> proc = subprocess.Popen ("ls /tmp")
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'])
<subprocess.Popen object at 0xb7c569ec>
>>> (ls output here)
Jeffrey
More information about the Python-list
mailing list