Reputation: 757
In node, I am running a perl script using child_process, and console.log in the callback seems to be behaving strangely.
child = exec("perl " + validationScript,
{cwd: myDir},
function(err, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
return cb(err);
});
stdout is printing correctly, but the stderr print statement is not executing. (If I comment out the stdout print, then stderr is printed correctly). So some buffering problem? How can I make them print correctly?
I am new to asynchronous programming, so sorry if this question is too basic.
Upvotes: 1
Views: 540
Reputation: 1237
have you tried it without return? The following code works for me. aa provokes an error and I have something on the stderr, if I only use ls I'll get no error but a correct stdout.
child = exec('ls aa',
function(err, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
cb(err);
});
function cb(data) {
console.log(data);
}
Upvotes: 1