Again, the same question. The reason is - I still can't make it work after reading the following:
http://stackoverflow.com/questions/527197/intercepting-stdout-of-a-subprocess-while-it-is-running
http://stackoverflow.com/questions/1606795/catching-stdout-in-realtime-from-subprocess
My case is that I have a console app written in C, lets take for example this code in a loop:
tmp = 0.0;
printf("\ninput>>");
scanf_s("%f",&tmp);
printf ("\ninput was: %f",tmp);
it continuously reads some input and writes some output.
My python code to interact with it is the following:
p=subprocess.Popen([path],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
p.stdin.write('12345\n')
for line in p.stdout:
print(">>> " + str(line.rstrip()))
p.stdout.flush()
So far whenever I read form p.stdout it alwais waits until the process is terminated and then outputs an empty string. I'v tride lots of stuff - but still the same result.
I tried Python 2.6 and 3.1, but the version doesn't matter - I just need to make it work somewhere.
Thanks in advance.