Benjamin4991
Benjamin4991

Reputation: 163

How to catch command line print output of git bash when calling from python?

Suppose I have 3 text files ours.txt, base.txt and theirs.txt and want to do a three way merge on them. When I call git merge-file -p ours.txt base.txt theirs.txt in Git Bash, it will print the merged text.

Whereas, when I run

import subprocess

dir = "path/to/text files"
cmd = ["git", "merge-file", "-p ", "ours.txt", "base.txt", "theirs.txt"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=dir)

I can access stdout and stderr through

(out, error) = p.communicate()

But can't seem to store the merged text that gets printed in Git Bash in a variable.

Does anybody have any ideas on how to retrieve it?

Thanks in advance.

Upvotes: 1

Views: 495

Answers (0)

Related Questions