[Tutor] Howto display progress as cmd is being executed via subprocess ?

Ramanathan Muthaiah rus.cahimb at gmail.com
Mon Jun 13 12:50:46 EDT 2016


Hello All,

Am aware of the module called 'progressbar' that can do this magic of
displaying progress as the cmd is executed.
In fact, I have a test code to show progress and tried, it works.

<progressbar code snippet>

from progressbar import *
import time

def main():
        progress = ProgressBar()
        for num in progress(range(80)):
                time.sleep(0.15)

if __name__ == '__main__':
        main()

And, I have this piece of code that executes set of cmds stored in 'cmd'
variable.
This too works without any issues until now.

try:
                 dlog = subprocess.check_output([cmd],
stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError, e:
                dlog = e.output

Question:

Am lost as to how to combine the progressbar and subprocess code snippets
to show the progress as the cmd is being executed.

Any ideas on how this can be done ?

--
regards
Ramanathan.M


More information about the Tutor mailing list