I could not get it worked yet while working part of a large Python script, so I will try to explain the required part only.
I am trying to git clone some repository with shell command using Python subprocess. It does clone the repo but does not shows the live/verbose output.
Example script that I try to do that:
# cat subprocess_git.py
#!/usr/bin/env python3
import subprocess
pub_repo = 'https://github.com/githubtraining/hellogitworld.git'
p = subprocess.Popen('git clone ' + pub_repo, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
while True:
output = p.stdout.readline().decode()
if output == '' and p.poll() is not None:
break
if output:
print(output.strip())
I get an output like this:
# python3 subprocess_git.py
Cloning into 'hellogitworld'...
But the difference when running directly on shell:
# git clone https://github.com/githubtraining/hellogitworld.git
Cloning into 'hellogitworld'...
remote: Enumerating objects: 306, done.
remote: Total 306 (delta 0), reused 0 (delta 0), pack-reused 306
Receiving objects: 100% (306/306), 95.82 KiB | 0 bytes/s, done.
Resolving deltas: 100% (69/69), done.
Is it possible to show all such output using Python subprocess?.