Is subprocess.Popen completely broken?

Lee Capps lcapps at cteresource.org
Thu Mar 27 16:09:52 CET 2008


On Mar 27, 2008, at 10:53 AM, Skip Montanaro wrote:

> I am trying to replace os.system calls with subprocess.Popen.  This  
> simple
> example fails miserably:
>
>>>> proc = subprocess.Popen ("ls /tmp")
> 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.
>

Try

proc = subprocess.Popen(('ls', '/tmp/'))

or

proc = subprocess.Popen('ls /tmp/', shell=True)

See http://docs.python.org/lib/node528.html

HTH,

---
Lee Capps
Technology Specialist
CTE Resource Center
lcapps at cteresource.org






More information about the Python-list mailing list