Read from stdouton Popen on WinXP?
mhenry1384 at gmail.com
Tue Aug 16 17:48:01 EDT 2005
I am trying to run a program and filter the output on Windows XP.
Since I want to filter the output, I'd like to read it a line at a time
and only print the lines I care about.
p = subprocess.Popen(["doxygen.exe", r"Doxyfile.cfg"],
line = p.stdout.readline()
if not line:
The problem is that readline() only returns after the whole process has
completed. I have tried various permutations such as using os.read()
and changing the bufsize parameter and using popen4. To no avail.
Obviously, it should be possible to read stdout before the process
completes, since if I leave off the "stdout=" parameter, the full
output shows up in stdout in "realtime" as you'd expect.
About the only thing I can come up with is to pipe the .exe to another
python script which could communicate to the main script via TCP/IP,
but that seems ridiculous. I searched the newsgroup and didn't see
anything particularly helpful.
Anyone have a non-ridiculous solution?
More information about the Python-list