Python shell scripts: invoking programs that use curses, etc.

Here is a very specific question, but I'm looking for a slightly more general solution:

I am writing a shell script in Python to help with various configuration tasks, including executing the git clone various repositories. When I call git clone , is there a good way to output git output directly to the terminal (progress bars, etc.)?

Just laying out the stdout subprocess in sys.stdout does not shorten it, because git behavior involves rewriting over the same part of the terminal, which indicates progress. So this is not very good:

 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 to "use git -python" - rather, I'm looking for a more general method that I can apply to this and other configuration tasks.

Thanks!

+4
source share
1 answer

Try:

 import os os.system(mycommand) 

This works for wget , a progress bar that rewrites itself on a single line on the screen works correctly this way. I believe this will work for git as well as for others.

+2
source

All Articles