I'm having problems redirecting stdio of another program using subprocess module. Just reading from stdout results in hanging, and Popen.communicate() works but it closes pipes after reading/writing. What's the easiest way to implement this?
I was playing around with this on windows:
import subprocess proc = subprocess.Popen('python -c "while True: print \'Hi %s!\' % raw_input()"', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: proc.stdin.write('world\n') proc_read = proc.stdout.readlinesreadline() for line in proc_read: if lineproc_read: print lineproc_read