Printing Stdout In Realtime From Subprocess
I want to print rather than catch the output from a bash command (more closer to real-time than this post). For instance, I have a script like this: from subprocess import Popen, P
Solution 1:
Try doing this way:
from subprocess import Popen, PIPE, STDOUT
cmd = 'rsync --rsh=ssh -rv thisdir/ servername:folder/'
p = Popen(cmd.split(), stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
print line
Note, that p.stdout
has hardcoded buffer (8192 bytes), if you want to start reading file at once, try this:
for line in iter(p.stdout.readline,''):
print line
Post a Comment for "Printing Stdout In Realtime From Subprocess"