When I install an npm module globally, I'm able to execute it in a child process with the exec method, but not with spawn.
So, this will print the version of Express (although sometimes it won't print anything because of this other issue)...
var exec = require('child_process').exec;
exec('express --version', function(err, stdout, stderr) {
console.log(stdout);
});
But if I use spawn instead:
var spawn = require('child_process').spawn;
spawn('express', ['--version']);
then I get this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
I believe this is only happening on Windows. I've seen this issue reported in other repos, like mocha-phantomjs, but it seems like a Node issue to me. Essentially, spawn is unable to find the command, but exec can. Shouldn't they work consistently?
I'm on Windows 7, using node v0.10.13.
When I install an npm module globally, I'm able to execute it in a child process with the
execmethod, but not withspawn.So, this will print the version of Express (although sometimes it won't print anything because of this other issue)...
But if I use
spawninstead:then I get this error:
I believe this is only happening on Windows. I've seen this issue reported in other repos, like mocha-phantomjs, but it seems like a Node issue to me. Essentially,
spawnis unable to find the command, butexeccan. Shouldn't they work consistently?I'm on Windows 7, using node v0.10.13.