joyent/node — pull request #7616 by edmorley (2014-05-13 13:09:06+00:00)
Title: child_process: use full path for cmd.exe on Win32

Currently child_process.exec() assumes that cmd.exe is on the PATH,
and fails with a spawn ENOENT error if it is not.

An example using Node v0.10.28 on Windows 8.1 x64, inside an MSYS bash shell (where the path is overridden by my .bashrc for other reasons):

**test.js:**
```node
var exec = require('child_process').exec,
child;

child = exec('echo "foo"',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
```
**Output:**
```
[/c/test]$ echo $PATH
.:/c/Python27:/c/Python27/Scripts:/mingw/bin:/bin:/c/Program Files/nodejs:/c/Users/Ed/AppData/Roaming/npm
[/c/test]$ node test.js
stdout:
stderr:
exec error: Error: spawn ENOENT
[/c/test]$ export PATH="$PATH:/c/Windows/System32"
[/c/test]$ node test.js
stdout: "foo"

stderr:
```

The Windows 'comspec' environment variable contains the full filepath
to the default command interpreter, eg "C:\Windows\System32\cmd.exe".
Should it not be set, we fall-back to using 'cmd.exe' from PATH, as
before.

This fixes issues downstream such as https://github.com/jharding/grunt-exec/issues/47