Again, the same question.
The reason is - I still can't make it work after reading the following:
- Real-time intercepting of stdout from another process in Python
- Intercepting stdout of a subprocess while it is running
- How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
- 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 always waits until the process is terminated and then outputs an empty string. I've tried 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.