Respond to git command line prompt from Python program
I’m currently using a Python program to make automated commits to a repository after it makes some edits to a file. I am using
subprocess.Popen to make a child process that calls the git binary. I though I could just use
stdin=PIPE when creating the child process and be able to write my user credentials when prompted by the command line, but for some reason this isn’t happening. The code looks like the following:
proc = Popen(["git","push","origin","master"], stdin=PIPE) proc.communicate("username") proc.communicate("password")
What’s happening right now is that it’s calling the binary but still showing me the command line prompt. I’ve taken a look at some other questions on here, but they are all using essentially the same code I am, so I’m a little stumped as to the problem. I know there are plenty of other ways of achieving this result, like caching my credentials, but I’m curious to see if this way can work for a number of reasons.
- Can't get stdout/stderr from (Python) subprocess.check_output()
- how to ammend the git commit message through python?
- Git add through python subprocess
- Using back-ticks in Python subprocess
- input inside script with Subprocess.call()
- Python subprocess.Popen to use git pager
One Solution collect form web for “Respond to git command line prompt from Python program”
proc = Popen(["git","push","origin","master"], stdin=PIPE,stdout=PIPE,stderr=PIPE) time.sleep(1) proc.stdin.write("username") time.sleep(1) proc.stdin.write("password") #or maybe for letter in "password": proc.stdin.write(letter) time.sleep(0.1) print proc.communicate()
something like that i guess …