[Tutor] subprocess Popen PIPE error
abhijeet.1989 at gmail.com
Tue Oct 26 15:44:33 CEST 2010
Please read the documentation of Popen. You cannot pass arguments like that.
>>> from subprocess import Popen,PIPE
>>> import shlex
>>> cmd="ls -l"
>>> p = Popen(cmd,stdout=PIPE,stderr=PIPE)
or simply that means
>>> p = Popen(['ls','-l'],stdout=PIPE,stderr=PIPE)
Hope I have made my point clear. The problem occuring is that there is no
binary that has name as "ls -l". Python cannot understand that "-l" is an
argument until you pass it this way.
On Tue, Oct 26, 2010 at 6:52 PM, Sean Carolan <scarolan at gmail.com> wrote:
> What am I doing wrong here?
> >>> from subprocess import Popen, PIPE
> >>> cmd = 'ls -l'
> >>> p = Popen(cmd, stdout=PIPE, stderr=PIPE)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib64/python2.4/subprocess.py", line 550, in __init__
> errread, errwrite)
> File "/usr/lib64/python2.4/subprocess.py", line 993, in _execute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
Abhijeet Rastogi (shadyabhi)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor