Is subprocess.Popen completely broken?

Discussion in 'Python' started by Skip Montanaro, Mar 27, 2008.

  1. 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
     
    Skip Montanaro, Mar 27, 2008
    #1
    1. Advertising

  2. 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
     
    Jeffrey Froman, Mar 27, 2008
    #2
    1. Advertising

  3. On Mar 27, 10:53 am, Skip Montanaro <> wrote:

    > Is subprocess.Popen completely broken?


    Your lack of faith in Python is somewhat disturbing ...
     
    Istvan Albert, Mar 27, 2008
    #3
  4. Skip Montanaro

    Martin Blume Guest

    "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
     
    Martin Blume, Mar 27, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michele Simionato

    subprocess.Popen

    Michele Simionato, Dec 12, 2004, in forum: Python
    Replies:
    5
    Views:
    17,700
  2. Ivo Woltring
    Replies:
    4
    Views:
    3,576
    Jeff Shannon
    Jan 27, 2005
  3. John Abel
    Replies:
    2
    Views:
    3,353
    John Abel
    May 12, 2005
  4. File.popen/IO.popen

    , May 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    244
    Robert Klemme
    May 20, 2006
  5. Doug McBride
    Replies:
    5
    Views:
    168
    Eric Hodel
    Jun 2, 2009
Loading...

Share This Page