There is a way to extend child_process events of nodejs it seems that some times events are not invoked so I want to see if the process was ended and then fire event. for example I use spawn and the process was succeeded but non of the following events was invoked, so can I track somehow via event or something when the spawn process was finished ?
function childProcessPromise(mtd, cmd, options) {
var child = child_process.spawn(cmd, value, opt);
child.stdout.on('data', function (data) {
console.log('data' + data);
});
child.stderr.on('data', function (data) {
console.log('test: ' + data);
reject(data);
});
child.on('close', function (code) {
console.log("close");
});
child.on('error', function (err) {
console.log(err);
});
});
}
The doc suggests what you're observing might be correct:
https://nodejs.org/api/child_process.html#child_process_event_close
Event: 'close'#
code Number the exit code if the child exited on its own. signal String the signal by which the child process was terminated. The 'close' event is emitted when the stdio streams of a child process have been closed. This is distinct from the 'exit' event, since multiple processes might share the same stdio streams.
Since by default the child streams are shared with the parent, the streams wont close as long as the parent is open
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
I have little experience with spawn and have not seen this hands on, but that's the way i'm interpreting the docs