Is subprocess.Popen completely broken?

Guilherme Polo ggpolo at gmail.com
Thu Mar 27 11:21:28 EDT 2008


2008/3/27, Skip Montanaro <skip at pobox.com>:
> > >  >>> proc = subprocess.Popen ("ls /tmp")
>  >
>  > proc = subprocess.Popen ("ls /tmp", shell=True)
>  >
>  > or
>  >
>  > proc = subprocess.Popen (["ls", "/tmp"])
>  >
>  > should work.
>
>
> Why should I need to set shell=True?

The default is shell=False, which means that Popen will use os.excevp
to execute your command, (talking about UNIX here), which in turn
expects a list as the "args" parameter, but you are passing a string.
Setting shell=True makes Popen execute the string passed through the shell.

> I'm not globbing anything.  The
>  second case still fails:
>
>  >>> proc = subprocess.Popen (["/usr/bin/ls" "/tmp"])

Notice how yours is lacking a comma separating the strings while mine
does include it.

>
> Traceback (most recent call last):
>
>   File "<stdin>", line 1, in ?
>   File "/opt/app/g++lib6/python-2.4/lib/python2.4/subprocess.py", line 542, in
>  __init__
>     errread, errwrite)
>   File "/opt/app/g++lib6/python-2.4/lib/python2.4/subprocess.py", line 975, in
>
> _execute_child
>     raise child_exception
>
> OSError: [Errno 20] Not a directory
>
>  Thx,
>
>
>  Skip
>
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves



More information about the Python-list mailing list