Skip to content

Commit 6c6cb65

Browse files
committed
fix: windows 8 doesn't support windows-kill
Fixes #1876
1 parent 5bb92d4 commit 6c6cb65

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/monitor/run.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var restart = null;
1616
var psTree = require('pstree.remy');
1717
var path = require('path');
1818
var signals = require('./signals');
19+
const osRelease = require('os').release();
1920

2021
function run(options) {
2122
var cmd = config.command.raw;
@@ -312,19 +313,26 @@ function kill(child, signal, callback) {
312313
}
313314

314315
if (utils.isWindows) {
316+
const taskKill = () => {
317+
try {
318+
exec('taskkill /pid ' + child.pid + ' /T /F');
319+
} catch (e) {
320+
utils.log.error("Could not shutdown sub process cleanly");
321+
}
322+
}
315323

316324
// We are handling a 'SIGKILL' POSIX signal under Windows the
317325
// same way it is handled on a UNIX system: We are performing
318326
// a hard shutdown without waiting for the process to clean-up.
319-
if (signal === 'SIGKILL') {
327+
if (signal === 'SIGKILL' || osRelease < 10) {
320328

321329
debug('terminating process group by force: %s', child.pid);
322330

323331
// We are using the taskkill utility to terminate the whole
324332
// process group ('/t') of the child ('/pid') by force ('/f').
325333
// We need to end all sub processes, because the 'child'
326334
// process in this context is actually a cmd.exe wrapper.
327-
exec(`taskkill /f /t /pid ${child.pid}`);
335+
taskKill();
328336
callback();
329337
return;
330338
}
@@ -357,9 +365,13 @@ function kill(child, signal, callback) {
357365
// Therefore we are using 'start' to create a new cmd.exe context.
358366
// The '/min' option hides the new terminal window and the '/wait'
359367
// option lets the process wait for the command to finish.
360-
execSync(
361-
`start "windows-kill" /min /wait "${windowsKill}" -SIGINT ${processId}`
362-
);
368+
try {
369+
execSync(
370+
`start "windows-kill" /min /wait "${windowsKill}" -SIGINT ${processId}`
371+
);
372+
} catch (e) {
373+
taskKill();
374+
}
363375
callback();
364376

365377
} else {

0 commit comments

Comments
 (0)