I'm trying to wrap a git clone
command with subprocess.Popen
(python3) and consume stdout in real-time. Something like
import subprocess
p = subprocess.Popen(
["git.exe", "clone", "https://github.com/llvm/llvm-project"],
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
for line in iter(p.stdout.readline, b""):
print(line)
which only produces the intial
b"Cloning into 'llvm-project'...\n"
and then "hangs" for quite a while. The problem seems to be that the clone command contains a lot of \r
lines which get buffered until the very end and flushed at once - I know the progress can be disabled but I do want them. I'd like to treat \r
like \n
somehow and continuously receive them. I tried read(1)
as well but it does not seem to do the trick.