943,559 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 671
  • Python RSS
Aug 15th, 2008
0

Opening pipelines with python ?

Expand Post »
In the Perl language, you can fork a child process with the following syntax
perl Syntax (Toggle Plain Text)
  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.
Reputation Points: 930
Solved Threads: 666
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Aug 18th, 2008
1

Re: Opening pipelines with python ?

Reputation Points: 56
Solved Threads: 65
Posting Whiz in Training
slate is offline Offline
242 posts
since Jun 2008
Aug 18th, 2008
0

Re: Opening pipelines with python ?

Thanks, it works very well this way
python Syntax (Toggle Plain Text)
  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")
Reputation Points: 930
Solved Threads: 666
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Aug 18th, 2008
0

Re: Opening pipelines with python ?

Thanks for the feedback.
Reputation Points: 56
Solved Threads: 65
Posting Whiz in Training
slate is offline Offline
242 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Identifying file types in python
Next Thread in Python Forum Timeline: New to Python, help printing output of system calls





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC