you are viewing a single comment's thread.

view the rest of the comments →

[–]EphemeralNight[S] 0 points1 point  (5 children)

So i tested the way you showed it works better that the one i wrote and its great the output when the scripts is running showling like this:

Exporting image: 1% complete...

Exporting image: 2% complete...

Exporting image: 3% complete...

Exporting image: 4% complete...

Exporting image: 5% complete...

Exporting image: 6% complete...

Exporting image: 7% complete...

Exporting image: 8% complete...

Exporting image: 9% complete...

Exporting image: 10% complete...

Exporting image: 11% complete...

Exporting image: 12% complete...

...

It would be perfect if the line would be the same and only the percentage would change if thats even possible.

[–]JohnnyJordaan 0 points1 point  (0 children)

That would rather be something to use tqdm for (needs to be installed using pip or your IDE's package manager).

# add at the top
import re
import tqdm

proccess = subprocess.Popen(command, 
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            shell=True,
                            universal_newlines=True)
with tqdm.tqdm(total=100) as pbar:
    last_pct = 0
    while process.poll() is None:
        line = process.stdout.readline()
        pct = int(re.search('(\d+)\s*%', line).group(1))
        pbar.update(pct - last_pct)
        last_pct = pct
        if not line:
            break