DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   Opening pipelines with python ? (http://www.daniweb.com/forums/thread140550.html)

Gribouillis Aug 15th, 2008 7:37 pm
Opening pipelines with python ?
 
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 ?

slate Aug 18th, 2008 11:38 am
Re: Opening pipelines with python ?
 
You can use subprocess with shell on unix.

http://blog.doughellmann.com/2007/07...ubprocess.html
And
http://www.python.org/doc/current/li...ubprocess.html

Gribouillis Aug 18th, 2008 1:19 pm
Re: Opening pipelines with python ?
 
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")

slate Aug 18th, 2008 2:11 pm
Re: Opening pipelines with python ?
 
Thanks for the feedback.


All times are GMT -4. The time now is 1:32 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC