[Tutor] subprocess Popen PIPE error

Abhijeet Rastogi 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"
>>> cmd=shlex.split(cmd)
>>> 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:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Abhijeet Rastogi (shadyabhi)
http://www.google.com/profiles/abhijeet.1989
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101026/e8e317cb/attachment.html>


More information about the Tutor mailing list