0

I am trying to run a git command with subprocess and store the output as a string. When I run the se commands in the interpreter, the git command prints its output but it is not stored. If I trade out 'git status' with 'ipconfig', the command runs flawlessly and I can retrieve its output.

>>> import subprocess as sp
>>> p = sp.Popen('git status', stdout = sp.PIPE) #this one prints the output of git status after the >>> prompt is printed.
>>> a = p.communicate()
>>> a #is a tuple of (b'', None)

How do I capture the output of git commands with subprocess? Please do not mark this as a duplicate because I have tried solutions from all over the place. Some are listed here:

How to preserve colors when capturing output from Git commands? https://www.pythonforbeginners.com/os/subprocess-for-system-administrators/

No matter what code I use, it does not work if applied to a git command. I use Windows 10 and Python 3.7.8.

AwesomeCronk
  • 421
  • 6
  • 16

0 Answers0