FAQ
Is there really no way to run a sub-process, gather its stdout/stderr,
and collect the return-code, on Win32???
But that's what the docs say...
These methods do not make it possible to retrieve the return code
from the child processes. The only way to control the input and
output streams and also retrieve the return codes is to use the
Popen3 and Popen4 classes from the popen2 module; these are only
available on Unix.
Surely not!?!?

Dave.

Search Discussions

  • Duncan Booth at Jun 7, 2004 at 3:01 pm
    Dave Sellars <dave at didnt.freeserve.co.uk> wrote in
    news:40c47dda$0$17461$afc38c87 at news.easynet.co.uk:
    Is there really no way to run a sub-process, gather its stdout/stderr,
    and collect the return-code, on Win32???
    But that's what the docs say...
    These methods do not make it possible to retrieve the return code
    from the child processes. The only way to control the input and
    output streams and also retrieve the return codes is to use the
    Popen3 and Popen4 classes from the popen2 module; these are only
    available on Unix.
    Surely not!?!?

    Dave.
    Bizarrely, the return code is returned as the result of the *last* call to
    the close method on any of the file handles returned. i.e. You must close
    all of stdin, stdout and stderr handles returned (usually after
    reading/writing), and the last one you close will return a numeric exit
    code if the command returned a non-zero exit code. If the command returned
    a 0 exit code then the final close returns None.
    from popen2 import popen2
    fout, fin = popen2("dir c:\\temp")
    print fout.close(), fin.close()
    None None
    fout, fin = popen2("dir c:\\xxx")
    print fout.close(), fin.close()
    None 1
    fout, fin = popen2("dir c:\\xxx")
    print fin.close(), fout.close()
    None 1
    >>>

    So far as I can see, the documentation omits to mention this little fact (I
    read the source).

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 7, '04 at 2:37p
activeJun 7, '04 at 3:01p
posts2
users2
websitepython.org

2 users in discussion

Duncan Booth: 1 post Dave Sellars: 1 post

People

Translate

site design / logo © 2022 Grokbase