How to use the python subprocess to get the latest commit id from master(git repo)

hari Source

I am unable to get the latest commit id from the master using the python subprocess task . Please note the details below.

Script details:

Release_Commit_result= subprocess.check_output("git", "log", "-1", "--pretty=format:","%H")

when I ran the script, I am getting following out put as,

OUtput:

Release_Commit_result= subprocess.check_output("git", "log", "-1", "--pretty=format:","%H")

File "/usr/lib/python2.7/subprocess.py", line 212, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)

TypeError:

init() got multiple values for enter code herekeyword argument 'stdout'

This git command alone actually gives the out put when it ran from the git bash.

pythongit

Answers

answered 3 months ago primef #1

Execute the command giving the arguments in an array or in a single string. Like this:

subprocess.check_output(["git", "log", "-1", "--pretty-format:%H"])

Please see https://docs.python.org/2/library/subprocess.html as reference.

UPDATE Edited command according to phd's suggestion, in the comments.

comments powered by Disqus