简体   繁体   中英

Terminating a child process in NodeJS on Windows

I have the following code, which launches 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. When I hit control-c to stop Node, the 'SIGINT' event handler fires and is supposed to close Flash. Instead, it says "Flash process killed", yet Flash is still open.

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.

How do I terminate my Flash process?

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. After launching Flash, it listened for signals on STDIN from my Node script. To terminate Flash and my custom launcher, I would write 'quit' to STDIN from Node onto my custom launcher exe. Worked like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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