Chaining programs with pipe

Grant Edwards grante at visi.com
Tue Aug 21 23:32:24 EDT 2007


On 2007-08-21, avishay <avishorp at yahoo.com> wrote:

> I'm trying to chain two programs with a pipe (the output of
> one feeding the input of the other). I managed to capture the
> output and feeding the input of each program independently
> with popen, but how do I tie them together?

On Unix, you do the same thing you would in C. Create a pipe
using os.pipe(), then run one program with stdout connected to
the "write" end of the pipe and the other program with stdin
connected to the "read" end of the pipe.

Or you can take a bit of a shortcut by letting the subprocess
module create the pipe for you:

http://docs.python.org/lib/node536.html

> Is there a solution that works equally on all platforms?

The doc page for subprocess doesn't say what platforms support
it.  I've had a lot of problems trying to use the subprocess
module on windows.  As is typical for Windows, there are all
sorts of special cases that either don't work at all or don't
work the way they should. You pays your money and you takes
your chances.

-- 
Grant Edwards                   grante             Yow!  Sorry, wrong ZIP
                                  at               CODE!!
                               visi.com            



More information about the Python-list mailing list