I need to start an external process that needs to be controlled using messages sent back and forth via stdin and stdout. Using subprocess.Popen I can start the process, but I can not control the execution via stdin, as I need.
The flow of what I'm trying to accomplish is as follows:
- Start external process
- Iterate for some steps
- Tell the external process to complete the next processing step by writing a new stdin
- Wait until the external process reports that it completed the step by writing a newline on it. stdout
- Close the external stdin process to indicate the external process that has completed execution.
I got the following:
process=subprocess.Popen([PathToProcess],stdin=subprocess.PIPE,stdout=subprocess.PIPE); for i in xrange(StepsToComplete): print "Forcing step # %s"%i process.communicate(input='\n')
When I run the above code, '\ n' is not passed to the external process, and I never go beyond step # 0. The blocks of code are on process.communicate () and do not proceed further. Am I using the communication () method incorrectly?
Also, how would I implement βwait until the external process writes a new lineβ, a piece of functionality?
source share