How to use subprocess
Thomas Bellman
bellman at lysator.liu.se
Wed Mar 23 06:46:44 EST 2005
Nicolas Fleury <nid_oizo at yahoo.com_remove_the_> writes:
> Hi,
> I want to use the subprocess module (or any standard Python module) to
> run a process:
> - which stdout and stderr can each be redirected to any file-like object
> (no fileno function).
> - can be cancelled with a threading.Event.
> My problem is that the subprocess.Popen constructor doesn't seem to
> support file-like objects (only file objects with fileno()).
> If I use subprocess.PIPE, I have the problem that the read functions of
> of the subprocess objects stdout and stderr are blocking (and I want to
> redirect them to different file-like objects, so I definitely need
> non-blocking access). How am I supposed to do it?
You might take a look at my asyncproc module, available at
http://www.lysator.liu.se/~bellman/download/asyncproc.py
Specifically the Process class. It doesn't do exactly what you
want, but maybe you can use it as inspiration for doing it yourself.
It requires the subprocess module, but I have successfully used
it under Python 2.3.2 with subprocess installed locally.
--
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"Adde parvum parvo magnus acervus erit" ! bellman @ lysator.liu.se
(From The Mythical Man-Month) ! Make Love -- Nicht Wahr!
More information about the Python-list
mailing list