Hi!
I'm trying to make two processes communicate using a pipe. I did this in the parent process:
process = subprocess.Popen(test, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
process.stdin.write("4\n");
output = process.stdout.read()
print output
and in the child process:
inp = raw_input()
integer = int(inp)
print integer**2
while(True):
pass
I would expect the parent process to print 16... Unfortunately, it remains hanging without printing anything. Replacing the infinite loop by a sleep for 5 seconds makes the parent process be idle for 5 seconds and AFTER that print 16. This shows that the parent process only gets the output from the child after it terminated execution.
I'd like to know if it's possible to get input before programs finishes. My idea is to go passing information via this pipe, getting input, processing it, and outputting the result in the pipe, so that the other can continue with processing.
Any help? Thanks,
Manuel