简体   繁体   English

在Windows上终止NodeJS中的子进程

[英]Terminating a child process in NodeJS on Windows

I have the following code, which launches Flash 我有以下代码,它将启动Flash

var flashExePath = "\"c:\\Program Files (x86)\\Adobe\\Adobe Flash CS6\\Flash.exe\"";

var sys = require('sys')
var exec = require('child_process').exec;
var flashProcess = exec(flashExePath);

... ... ... ……

function KillFlash()
{
    console.log("Terminating Flash...")
    if(flashProcess && flashProcess.exit)
    {
        flashProcess.exit(1);
        console.log("Flash process killed")
    }
}

... ... ... ……

process.on('SIGINT', function() {
    KillFlash();
    console.log('Exiting...');
    process.exit(1);
});

The KillFlash function is supposed to terminate the Flash process. KillFlash函数应该终止Flash进程。 When I hit control-c to stop Node, the 'SIGINT' event handler fires and is supposed to close Flash. 当我按Control-c停止Node时,“ SIGINT”事件处理程序将触发并应关闭Flash。 Instead, it says "Flash process killed", yet Flash is still open. 而是显示“ Flash进程已终止”,但Flash仍处于打开状态。

I've tried: 我试过了:

flashProcess.kill()
flashProcess.kill('SIGINT')
flashProcess.kill('SIGTERM')
flashProcess.exit()
flashProcess.exit(1)

None of these seem to work; 这些似乎都不起作用。 NodeJS closes but Flash still remains open. NodeJS关闭,但Flash仍保持打开状态。

How do I terminate my Flash process? 如何终止Flash过程?

I didn't really fix the problem but I came up with a workaround. 我并没有真正解决问题,但是我想出了一种解决方法。

I wrote an app in C# whose sole purpose was to launch and monitor the Flash executable. 我用C#编写了一个应用程序,其唯一目的是启动和监视Flash可执行文件。 After launching Flash, it listened for signals on STDIN from my Node script. 启动Flash之后,它从我的Node脚本中侦听STDIN上的信号。 To terminate Flash and my custom launcher, I would write 'quit' to STDIN from Node onto my custom launcher exe. 要终止Flash和我的自定义启动器,我将“退出”到STDIN从Node写入我的自定义启动器exe。 Worked like a charm. 像魅力一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM