【发布时间】:2018-02-26 01:51:40
【问题描述】:
所以我正在开发一个应在按下按钮时启动外部应用程序的电子应用程序。它可以工作,但如果我关闭该应用程序并再次按下按钮,它将启动该过程的几个实例。代码如下:
ipcMain.on("run_crystal", () => {
var cp = require("child_process");
executablePath = crystal + "\\CrystalDM\\Server\\CrystalDMServer.exe";
var Server_child = cp.spawn(executablePath);
executablePath = crystal + "\\CrystalDM\\Game\\CrystalDM.exe";
var parameters = ["test"];
var options = {cwd:crystal+"\\CrystalDM\\Game"};
console.log("a intrat in start game si urmeaza sa ruleze " + executablePath)
var Game_child = cp.execFile(executablePath, parameters, options, (error, stdout, stderr) =>{
console.log(stdout)
Game_child.kill("SIGINT");
Server_child.kill("SIGINT");
delete Game_child;
delete Server_child;
delete cp;
});
});
【问题讨论】:
-
.. 你的预期行为是什么?
-
例如,它应该用于像 Steam 这样的平台。你点击播放,它开始游戏。但是在这种情况下,您可能会发现自己处于想要第二次甚至第三次击球的情况。好吧,按照当时的代码方式,它会开始运行游戏的多个实例。但几乎没有修复它。
标签: javascript node.js electron child-process