views:

38

answers:

1

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
+2  A: 

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.

Bryan Oakley
I just added an "update" to the question.
Vladimir Prudnikov
*which* also checks if the file is executable by the current user.
Roger Pate
yep, problem was related to $PATH which was different (why?) from TextMate and our app.
Vladimir Prudnikov