为什么childprocess无法捕获'SIGINT'

时间:2013-08-25 09:39:52

标签: node.js

father.js
var spawn = require('child_process').spawn;
var child = spawn('node',['child.js']); 

setInterval(function(){
  child.kill('SIGINT');
},2000);

child.on('exit',function(code,signal){
 console.log('process exit '+code+' '+signal);
});

child.js
process.stdin.resume();
process.on('SIGINT', function() {
  console.log('Got SIGINT. Press Control-D to exit.');
});

节点版本:0.10.17

为什么childprocess无法捕获'SIGINT'? 但如果你单独运行节点child.js,它可以为ctrl + c终止cmd的cathch信号。

1 个答案:

答案 0 :(得分:1)

确实得到了SIGINT!只是你没有听到子进程输出。在father.js中添加这一行来查看它。

child.stdout.pipe(process.stdout);
相关问题