I'm attempting to do something I think is very simple -- execute an 'echo' line using child_process.exec. My code looks as such:
var exec = require('child_process').exec;
exec('echo "HELLO"', function (error, stdout, stderr) {
console.log(error);
console.log(stdout);
console.log(stderr);
});
As of now, the echo is never being called and neither is the callback. Is there something I'm missing here?
Also, I'm using thins inside a grunt task I'm creating, so I'm not sure if there's anything there that could set it off (though this plugin seems to be doing it fine here --https://github.com/sindresorhus/grunt-shell/blob/master/tasks/shell.js)
Your code is good.
The problem you have is probably about the callback, if you use execSync
of child_process it will probably work.
If you want to keep exec
function with callback in your grunt task, use this.async();
const done = this.async();
exec('echo "HELLO"', function (error, stdout, stderr) {
console.log(error);
console.log(stdout);
console.log(stderr);
done();
});
Have a look here: https://gruntjs.com/api/inside-tasks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With