Pythonic tee for subprocess module.

Joe Blow mightybastion at gmail.com
Tue Nov 13 20:24:40 EST 2007


I'd like to use the subprocess module to create a pipeline with a
fork.  For example, what if I wanted a "cat" process to send a file to
both an "md5sum" process and a "gzip" process.  In bash, I'd do
something like this:

> cat source_file | tee >(md5sum > source_file.md5sum) | gzip -c > source_file.gz

What is the best way to "tee" a Python file object so that I can send
it to two different subprocess.Popen instances?  I tried creating a
Tee class with read and write methods that send duplicate data to a
number of file objects, but the Popen class won't accept my class as
an argument to the stdin parameter.  subprocess.Popen seems to require
_real_ file objects with file descriptors, etc., not just any class
with a read() and write() method.

Suggestions anyone?  Thanks for your help.

--Ethan



More information about the Python-list mailing list