我正在使用此節點的js代碼來運行包含無限循環的App.exe文件。我通過輸入並從App.exe獲取輸出。使用節點j關閉.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嗎? – robertklep