popen2.Popen3 on Windows
Ian McConnell
ian at emit.demon.co.ukx
Tue Jun 17 03:39:23 EDT 2003
Peter Hansen <peter at engcorp.com> writes:
> Justin Johnson wrote:
>>
>> 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?
>
> You might get more or better replies if you create your posting as
> a new one, rather than replying to an existing one and changing the
> subject. Many news and mail readers will do "threading" which means
> your article will show up as part of the discussion to which you
> replied, and many people will have killed that thread (and thus
> never see your question) by now.
Have a look at the process package on
http://starship.python.net/~tmick/
process.py is a (rather large) Python module to make process control easier
and more consistent on Windows and Linux. The current mechanisms (os.popen*,
os.system, os.exec*, os.spawn*) all have limitations.
A quick list of some reasons to use process.py:
* You don't have to handle quoting the arguments of your command line.
You can pass in a command string or an argv.
* You can specify the current working directory (cwd) and the
environment (env) for the started process.
* On Windows you can spawn a process without a console window opening.
* You can wait for process termination or kill the running process
without having to worry about weird platform issues. (Killing on
Windows should first give the process a chance to shutdown cleanly.
Killing on Linux will not work from a different thread than the
process that created it.)
* ProcessProxy allows you to interact in a pseudo-event-based way with
the spawned process. I.e., you can pass in file-like object for any of
stdin, stdout, or stderr to handle interaction with the process.
--
"Thinks: I can't think of a thinks. End of thinks routine": Blue Bottle
** Aunty Spam says: Remove the trailing x from the To: field to reply **
More information about the Python-list
mailing list