Cmd output and status in one call on Windows

Richard rshaw2 at midsouth.rr.com
Tue Jun 17 09:41:54 EDT 2003


"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).




More information about the Python-list mailing list