Chaining programs with pipe
Karthik Gurusamy
kar1107 at gmail.com
Tue Aug 21 23:58:13 EDT 2007
On Aug 21, 8:33 pm, Grant Edwards <gra... at visi.com> wrote:
> On 2007-08-22, Karthik Gurusamy <kar1... at gmail.com> wrote:
>
> > 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')
> > ' 4 4 24'
>
> Executing a shell just because you want a pipe seems like a bit
> of overkill. Doing it the "right" way with subprocess is
> pretty trivial.
Probably I should've put extra stress on the word "reuse".
The example quoted was trivial; if you replace the pipeline to have
say 5 processes, the advantage of not-reinventing the wheel becomes
more obvious.
I would call hand-crafting the pipe-setup an "overkill" when a very
good solution already exists to solve the problem. Yes, it may be
trivial to do; but not simpler than delegating to a shell.
Karthik
>
> --
> Grant Edwards grante Yow! I was born in a
> at Hostess Cupcake factory
> visi.com before the sexual
> revolution!
More information about the Python-list
mailing list