How to use subprocess

Thomas Bellman bellman at
Wed Mar 23 12:46:44 CET 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

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 @
          (From The Mythical Man-Month)       ! Make Love -- Nicht Wahr!

More information about the Python-list mailing list