Cmd output and status in one call on Windows
db3l at fitlinxx.com
Wed Jun 18 01:38:31 CEST 2003
"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
This should work from Python 2.0 through 2.3.
More information about the Python-list