FAQ
Hi,

I need a way to run an external command, grab its output (stdout,stderr)
and get a return status for the command. It seems like popen2.Popen3
(Note the upper case "P") is the way to do this, but it only works on
unix. Is there a way to get this info on Windows?

Thanks.
-Justin

Search Discussions

  • Richard at Jun 17, 2003 at 1:41 pm
    "Justin Johnson" <justinjohnson at fastmail.fm> wrote in message news:<mailman.1055786077.30359.python-list at python.org>...
    Hi,

    I need a way to run an external command, grab its output (stdout,stderr)
    and get a return status for the command. It seems like popen2.Popen3
    (Note the upper case "P") is the way to do this, but it only works on
    unix. Is there a way to get this info on Windows?

    Thanks.
    -Justin
    I'm not sure about the return status (errorlevel in windows). But
    "pexpect" would work for your situation. It's mainly used for
    interactive commandline programs, but it has a run function
    (pexpect.run) which will run the command and returns the output as a
    string. You may need to use the more general class spawn
    (pexpect.spawn).
  • Noah at Jun 18, 2003 at 7:27 pm
    rshaw2 at midsouth.rr.com (Richard) wrote in message news:<84e0f331.0306170541.45015058 at posting.google.com>...
    "Justin Johnson" <justinjohnson at fastmail.fm> wrote in message news:<mailman.1055786077.30359.python-list at python.org>...
    Hi,

    ... Is there a way to get this info on Windows?

    Thanks.
    -Justin
    I'm not sure about the return status (errorlevel in windows). But
    "pexpect" would work for your situation. It's mainly used for
    ...
    Alas, Pexpect is for UNIX; although, it works under Cygwin.

    Yours,
    Noah
  • David Bolen at Jun 17, 2003 at 11:38 pm

    "Justin Johnson" <justinjohnson at fastmail.fm> writes:

    I need a way to run an external command, grab its output (stdout,stderr)
    and get a return status for the command. It seems like popen2.Popen3
    (Note the upper case "P") is the way to do this, but it only works on
    unix. Is there a way to get this info on Windows?
    One option (that doesn't seem to have gotten documented when it was
    introduced in Python 2.0, so you can decide if you want to depend on
    it), is that under Windows only, all os.popen#() functions will return
    the return status for the child process as a result of the close().
    In the case of # >= 2, when you get back multiple handles, you get the
    return status as the result of the close() method whichever handle you
    close last.

    This should work from Python 2.0 through 2.3.

    -- David

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 16, '03 at 5:53p
activeJun 18, '03 at 7:27p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase