1

git is installed on windows and works from any directory (it is in System path)

var child_process = require('child_process');
child_process.exec('git --version', function(err, stdout, stderr) {
  // stdout is correct - git version 1.7.11.msysgit.1
  // but err is not null
  // err is [Error: Command failed: ] killed: false, code: 1, signal: null }      
}

What can cause this?

6
  • i dont have git installed on windows but perhaps git \version is the proper syntax? Commented Aug 24, 2013 at 20:40
  • git --version works to on windows. I think it can not find git but I don't understand why Commented Aug 24, 2013 at 20:43
  • how irritating! perhaps as a workaround you might pass {env:{PATH:"C:\path to\node"}} as the options argument to process.exec() as described in docs. other than that I have no experience with Windows environment variables, thus no further ideas :/ Commented Aug 24, 2013 at 21:11
  • It's in my computer's path (on Windows), and your code worked for me. I did have to make sure that I restarted the shell that I was using for my NodeJS development. stdout = git version 1.8.3.msysgit.0 Commented Aug 24, 2013 at 21:14
  • Actually - restarting the shell might have been the solution, not my snippet... I think that the shell does not source environment variables dynamically. So if you didn't restart the shell between adding the dir to Windows PATH and posting the question, remove my snippet and see if it still works Commented Aug 24, 2013 at 21:52

2 Answers 2

3

I had this issue using Windows 7 with msysgit. Two things seem to solve the issue.

First, verify that your Path system variable includes a path to the Git bin directory, and not the cmd directory:

C:\Program Files (x86)\Git\bin

Next, verify you have a recent version of msysgit. I've verified the issue as solved with version 1.8.4-preview:

https://code.google.com/p/msysgit/downloads/list

Restart your shell and try again.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, this just happened to me after installing newest Git. 😣 Thanks!
1

As a workaround you can pass {env:{PATH:"C:\path to\node"}} as the options argument to process.exec(cmd, opts, callback) as described in docs. I am surprised that the Windows path doesn't carry over but have no explanation why.

1 Comment

I've added in OP, there is not problem with PATH. It just can not execute git without err.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.