Chaining programs with pipe

Gabriel Genellina gagsl-py2 at
Wed Aug 22 04:56:18 CEST 2007

On 21 ago, 21:40, Karthik Gurusamy <kar1... at> wrote:
> On Aug 21, 3:09 pm, avishay <avish... at> 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? Is there a solution that works equally on all
> > platforms?
> Not sure on non-unix platforms, but in unix like platforms it's best
> to reuse shell's power.
> >>> import commands
> >>> commands.getoutput('ls | wc')

Using the shell is OK but I think the subprocess module is more
portable. This example is on Windows:

import subprocess"dir /b | sort", shell=True)

2A0B17.dmp [...]

Gabriel Genellina

More information about the Python-list mailing list