Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is subprocess.Popen completely broken?

Reply
Thread Tools

Is subprocess.Popen completely broken?

 
 
Skip Montanaro
Guest
Posts: n/a
 
      03-27-2008
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.

Frustrated in Chicago...

Skip


 
Reply With Quote
 
 
 
 
Jeffrey Froman
Guest
Posts: n/a
 
      03-27-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
 
Reply With Quote
 
 
 
 
Istvan Albert
Guest
Posts: n/a
 
      03-27-2008
On Mar 27, 10:53 am, Skip Montanaro <s...@pobox.com> wrote:

> Is subprocess.Popen completely broken?


Your lack of faith in Python is somewhat disturbing ...

 
Reply With Quote
 
Martin Blume
Guest
Posts: n/a
 
      03-27-2008
"Istvan Albert" schrieb
>
> > Is subprocess.Popen completely broken?

>
> Your lack of faith in Python is somewhat
> disturbing ...
>

I have consistently made the experience that when
I was about to ask "is X completely broken", the
error was on my side.

Martin


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: VOIPfone down completely ... I mean very completely !! cjd UK VOIP 2 10-10-2008 01:17 PM
Etching tutorials-or now for something completely different Technoholic Case Modding 71 09-27-2005 06:39 AM
Help! How can I let Intel Proset completely control my wirelss? networm Wireless Networking 3 09-26-2005 03:11 AM
USB NIC Group Policy not applying completely Microsoft News Wireless Networking 0 03-11-2005 12:56 AM
Completely update mailboxes (Mozilla mail) Gwen Morse Firefox 0 02-07-2004 08:05 AM



Advertisments