简体   繁体   中英

Reading STDOUT of subprocess

Hello I want to read output of command which gives progress bar like output as show below

10% |****                       | 3:56 ETA

I tried with following code

import subprocess
import sys
proc = subprocess.Popen("command", shell=True, stdout=subprocess.PIPE)
while True:
    line = proc.stdout.readline()
    if not line:
        break
    split = line.rstrip()
    print line
    print "\n"
print "Done"

This code reads output after completion of progress bar to 100%, but I want to read it at intermediate. Can any one help?

You're using readline() but the progress bar is all printed on one line, so readline() waits until the progress bar has been fully printed, as that is when a line break occurs. Try read(1) to get a character at a time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM