I use child_process.exec
to run npm init
, I can let it create package.json, but after creating, my stdin seems still open, I want to know when my child process finished so I maybe close the stdin, but I could not know when it finished.
Here is my code:
var child = exec('npm init', function (err, stdout, stderr) {
console.log('over');
});
child.stdout.on('data', function(data) {
process.stdout.write(data);
//process.stdin.resume();
});
child.stdout.on('end', function() {
console.log('end out');
});
child.stdout.on('close', function() {
console.log('close out');
});
child.on('exit', function() {
console.log('exit');
});
child.on('close', function() {
console.log('close');
});
child.on('disconnect', function() {
console.log('disconnect');
});
// read stdin and send to child process
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if(chunk !== null) {
child.stdin.write(chunk);
}
});
None of events fired after it finishing create package.json, so how to close it when it finished?