Opening pipelines with python ?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is online now Online
Posting Shark

Opening pipelines with python ?

 
0
  #1
Aug 15th, 2008
In the Perl language, you can fork a child process with the following syntax
  1. open CHILD, " | programA | programB | program C";
  2. 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 ?
Last edited by Gribouillis; Aug 15th, 2008 at 7:40 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 128
Reputation: slate is an unknown quantity at this point 
Solved Threads: 31
slate slate is offline Offline
Junior Poster

Re: Opening pipelines with python ?

 
1
  #2
Aug 18th, 2008
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is online now Online
Posting Shark

Re: Opening pipelines with python ?

 
0
  #3
Aug 18th, 2008
Thanks, it works very well this way
  1. import subprocess
  2. child = subprocess.Popen( " progA | progB | progC",
  3. shell = True,
  4. stdin = subprocess.PIPE,
  5. )
  6. child.stdin.write("example input\n")
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 128
Reputation: slate is an unknown quantity at this point 
Solved Threads: 31
slate slate is offline Offline
Junior Poster

Re: Opening pipelines with python ?

 
0
  #4
Aug 18th, 2008
Thanks for the feedback.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 529 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC