I'm trying to run the command git branch | grep \*
like so:
require('child_process').exec('git branch | grep \*', function(err){
console.log(err);
});
but I keep getting the error { [Error: Command failed: ] killed: false, code: 1, signal: null }
Why is this happening and how can I do this?
It means grep return code is 1 and grep got nothing.
You can just write a simple code that return 1 and run it by exec in node.js and you will get the same result as above.
You can check the status code by err.code, and do something like reporting empty result in your callback function.
Is the stout value in the callback returning anything? Try doing this:
require('child_process').exec('git branch | grep \*', function(err,stout,sterr){
console.log(err);
console.log(stout);
console.log(sterr);
});
Might give you some insight on exactly what's going on...
Are you trying to run grep \*
? remember you have to escape backslashes in strings.