running a pipe of commands from python

Fredrik Lundh fredrik at effbot.org
Wed Dec 13 02:56:52 EST 2000


Harald Kirsch wrote:
> In Tcl I just write
>
>    exec doThis | doThat |toMore | finishUp >output <input 2>errors
>
> In the Python reference manual I find os.exec(), os.fork(), popen2()
> etc, but none of these is as easy to use as Tcl's exec. What is
> Python's equivalent (and I am sure there must be somehting)?

you don't say what output, input and errors are, so it's
not obvious what you're looking after.

if they're filenames, use:

    os.system("doThis | doThat >output ...")

if they're file handles, use os.popen3:

    input, output, errors = os.popen3("doThis | doThat")

for a more general (but unix-only) solution, see:
http://www.python.org/doc/current/lib/module-pipes.html

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->






More information about the Python-list mailing list