我正在使用此 Node 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 运行
最佳答案
您可以直接生成后者,而不是生成 cmd.exe
来生成 App.exe
:
bat = spawn('App.exe');
关于javascript - 使用node js关闭.exe文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45892837/