linux - Periodically getting output of a bash command in Python -
i writing gui wrapper bash command in python. when bash command run, first 3-4 lines constant, , last line overwritten display progress in textual format. want convert progress progress bar python based gui.
how retrieve progress of bash command periodically? other similar answers retrieve first few constant lines, fail fetch last line periodically changing.
if reading input using process.stdout.readline()
won't fetch progress until entire line printed stdout. instead can read stdout streaming character character given below
import subprocess import sys process = subprocess.popen("ls", stdout=subprocess.pipe) c in iter(lambda: process.stdout.read(1), ''): sys.stdout.write(c)
Comments
Post a Comment