I’m using Python’s subprocess.communicate() to read stdout from a process that runs for about a minute.
How can I print out each line of that process’s stdout in a streaming fashion, so that I can see the output as it’s generated, but still block on the process terminating before continuing?
subprocess.communicate() appears to give all the output at once.
Please note, I think J.F. Sebastian’s method (below) is better.
Here is an simple example (with no checking for errors):
If
lsends too fast, then the while loop may end before you’ve read all the data.You can catch the remainder in stdout this way: