2

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.

thfabian
  • 125
  • 9
  • Does this answer your question? [How to get subprocess stdout while running git command?](https://stackoverflow.com/questions/25986533/how-to-get-subprocess-stdout-while-running-git-command) – Maurice Meyer Feb 03 '21 at 21:05
  • Or: https://stackoverflow.com/questions/23155452/read-git-clones-output-in-real-time – Maurice Meyer Feb 03 '21 at 21:06

0 Answers0