Here’s a very specific question, but I’m looking for a slightly more general solution:
I’m writing a shell script in Python to assist in various config tasks, including performing a git clone of various repositories. When I call git clone, is there a good way for me to supply git display output directly to the terminal (progress bars, etc)?
Just piping the subprocess’s stdout to sys.stdout doesn’t cut it, because git‘s behavior involves re-writing over the same portion of the terminal to indicate progress. So this isn’t really good enough:
import sys, subprocess
process = subprocess.Popen("git clone --recursive https://github.com/my/repo.git",
shell=True,
stdout=sys.stdout,
stderr=subprocess.PIPE)
I’m not looking for the answer “use git-python” — rather, I’m looking for a more general technique that I can apply to this and other config tasks.
Thanks!
Try:
This works for
wget, the progress-bar that rewrites itself on one line on the screen works correctly this way. I suppose it would work forgitand others as well.