I am trying to talk to a child process using the python subprocess.Popen () call. In my real code, I implement the IPC type, so I want to write some data, read the answer, write some more data, read the answer, and so on. Because of this, I cannot use Popen.communicate (), which otherwise works well for a simple case.
This code shows my problem. He does not even receive the first answer, freezes at the first "reading result". What for? How can I do this work as I expect?
import subprocess p = subprocess.Popen(["sed", 's/a/x/g'], stdout = subprocess.PIPE, stdin = subprocess.PIPE) p.stdin.write("abc\n") print "Reading result:" print p.stdout.readline() p.stdin.write("cat\n") print "Reading result:" print p.stdout.readline()
Mats Ekberg
source share