The subprocess
module allows you to attach pipes to the stdout and stderr of your spawned process. It's a bit complicated but if you know the output of that process very well, you can poll the output generated through the pipe at specific intervals and then increment a progressbar accordingly. Then again, if that process generates console output anyway, why not implement a progressbar there?
Edit to show how this could be done. args
is a list with your command and its arguments.
import subprocess
sub = subprocess.Popen(args, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
while sub.poll() is None:
output = sub.stdout.read() # get all of current contents
if output:
# ... process output and decide how far the process has advanced
# ... advance your progressbar accordingly
else:
time.sleep(1E-01) # decide on a reasonable number of seconds to wait before polling again
if sub.returncode != 0:
err = sub.stderr.read()
# ... decide what to do
If you can modify the sub process I suggest you do the progress there.