Vladimir Prudnikov
Vladimir Prudnikov

Reputation: 7242

How to get path to the installed GIT in Python?

I need to get a path to the GIT on Max OS X 10.6 using Python 2.6.1 into script variables. I use this code for that:

r = subprocess.Popen(shlex.split("which git"), stdout=subprocess.PIPE)
print r.stdout.read()

but the problem is that output is empty (I tried stderr too). It works fine with another commands such as pwd or ls.

Can anyone help me with that?

UPDATE: When I run which git from Terminal it prints out path as expected. So, which can find it.

UPDATE 2: I just created the bash script

#!/usr/bin/env bash
GP=`/usr/bin/which git`
PWD=`pwd`
echo "PATH IS: ${GP}"
echo "PWD IS: ${PWD}"

and output is

PATH IS: 
PWD IS: /Users/user/tmp

Upvotes: 2

Views: 292

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386220

All which does is iterate over the directories in $PATH, checking to see if the file is there. Just write a small method to do likewise.

Upvotes: 2

Related Questions