使用节点jsclosures.exe文件

我正在使用此节点的js代码来运行包含无限循环的App.exe文件。 我通过input并从App.exe获取输出。

var bat = null; app.post("/api/run", function(req, res) { if(req.body.success) { if(bat) bat.kill(); } if(!bat) { bat = spawn('cmd.exe', ['/c App.exe']); bat.stderr.on('data', function (data) { res.end(JSON.stringify({error: true, message: data.toString()})); }); bat.on('exit', function (code) { bat = null; console.log('Child exited with code ' + code); res.end(JSON.stringify({error: false, message: "Application Closed!"})); }); } bat.stdin.write(req.body.input+'\n'); bat.stdout.once('data', function (data) { console.log(data.toString()); res.end(JSON.stringify({error: false, message: data.toString()})); }); }); 

问题是我成功的时候杀了subprocesssubprocess被杀死了,但是App.exe一直在运行。 我有什么办法阻止App.exe运行

而不是派生出产生App.exe cmd.exe ,你可以直接产生后者:

 bat = spawn('App.exe'); 

为了杀死node.js中产生的进程,你需要使用SIGINT

 bat.kill('SIGINT'); 

在signal7中可以find所有POSIX信号的列表以及它们的作用