我使用这个节点的js代码来运行包含无限循环的App.exe文件。我传递输入并从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()}));
});
});
问题是,在成功的情况下,当我杀除子进程时,子进程会被杀死,但App.exe仍在运行。我有没有办法阻止App.exe参选
发布于 2017-08-26 15:19:33
您可以直接生成App.exe
,而不是生成生成App.exe
的cmd.exe
:
bat = spawn('App.exe');
发布于 2017-08-26 15:16:28
为了杀死node.js中衍生的进程,您需要使用SIGINT
。
bat.kill('SIGINT');
所有POSIX信号及其作用的列表可在signal7上找到
https://stackoverflow.com/questions/45892837
复制相似问题