In the Perl language, you can fork a child process with the following syntax

open CHILD, " | programA | programB | program C";
print CHILD "this is an example input";

(at least, you can do this under linux). This statement starts 3 processes in fact; programA, B and C. Moreover, the stdout of A is piped to the stdin of B and the stdout of B is piped to the stdin of C, forming a pipeline. Since the command starts, with a "|", CHILD is a pipe through which your program can write in the stdin of A.

I'd like to know if a similar construct exists for python, or, suppose I want to achieve the same effect with python, what would be the best way to do it ?

8 Years
Discussion Span
Last Post by slate
Featured Replies
  • 1

    You can use subprocess with shell on unix. [URL="http://blog.doughellmann.com/2007/07/pymotw-subprocess.html"]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/URL] And [URL="http://www.python.org/doc/current/lib/module-subprocess.html"]http://www.python.org/doc/current/lib/module-subprocess.html[/URL] Read More


Thanks, it works very well this way

import subprocess
child = subprocess.Popen( " progA | progB  |  progC",
  shell = True,
  stdin = subprocess.PIPE,
child.stdin.write("example input\n")
This question has already been answered. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.