import subprocess
proc = subprocess.Popen('git status')
print 'result: ', proc.communicate()
I have git in my system path, but when I run subprocess like this I get:
WindowsError: [Error 2] The system cannot find the file specified
How can I get subprocess to find git in the system path?
Python 2.6 on Windows XP.
The problem you see here is that the Windows API function CreateProcess, used by subprocess under the hood, doesn’t auto-resolve other executable extensions than
.exe. On Windows, the ‘git’ command is really installed asgit.cmd. Therefore, you should modify your example to explicitly invokegit.cmd:The reason
gitworks whenshell==Trueis that the Windows shell auto-resolvesgittogit.cmd.Eventually, resolve git.cmd yourself: