I use the node child_process API
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
var child = child_process.spawn(cmd, val, options);
from the child I use the following
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
Can I add inside those pipe event some code inside like console.log?
like for example maybe with prototype
child.on('error', function(err) {
console.log(err);
});
update
What I need that is to listen to this childProcess.stderr.pipe(process.stderr);
and In case I got and error do process.exit(1)
when I try something like I got error
child.stderr.pipe(function () {
console.log("im here");
process.stderr;
process.exit(1);
}
);
UPDATE2
I try the following
var child = child_process.spawn(cmd, value, opt);
child.stdout.on('data', function (data) {
console.log("IM HERE");
console.log('data' + data);
});
child.stderr.on('data', function (data) {
console.log("IM HERE");
console.log('test: ' + data);
reject(data);
});
child.on('close', function (code) {
console.log("IM HERE");
console.log("close");
});
child.on('error', function (err) {
console.log("IM HERE");
console.log(err);
});
child.stderr.on('error', function (err) {
console.log("IM HERE");
console.log("my Erorr");
process.stderr.emit('error', err);
});
child.stdout.on('data', function (buf) {
console.log("IM HERE");
console.log('buf receive');
console.log(buf.toString());
});
//Just when I add the following I see the error in the log
child.stderr.pipe(process.stderr)
Non of the console.log("im here") is printed in case of error
I need somehow to listen to this pipe or maybe to extend somehow the child.stderr.pipe(process.stderr), what I need is to do process.exit(1)
in case I got error from the code statement above...
Maybe with javascript prototype but not sure how to do that...
Please assist Im stuck and I know this is not simple...