Skip to content

Commit

Permalink
Use taskkill instead of .kill() on Windows
Browse files Browse the repository at this point in the history
Solution to arjunmehta#10
Inspired by nodejs/node#3675
  • Loading branch information
efokschaner authored May 19, 2019
1 parent 7167a50 commit 367e2fa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Spawn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var spawn = require('child_process').spawn;
var child_process = require('child_process');

function Spawn(stream, command, args, name, output) {
var exited = false;
Expand All @@ -13,7 +13,7 @@ function Spawn(stream, command, args, name, output) {
};
}

spawnedProcess = spawn(command, args, options);
spawnedProcess = child_process.spawn(command, args, options);

this.id = name;

Expand Down Expand Up @@ -52,7 +52,13 @@ function Spawn(stream, command, args, name, output) {

process.on('exit', function(code) {
if (exited === false) {
spawnedProcess.kill();
if (process.platform === 'win32') {
// Workaround for kill() not propagating to children of the cmd.exe we launched
// see https://github.com/nodejs/node/issues/3675#issuecomment-288578092
child_process.exec('taskkill /F /T /PID ' + spawnedProcess.pid);
} else {
spawnedProcess.kill();
}
}
});

Expand Down

0 comments on commit 367e2fa

Please sign in to comment.