fix(cli): hide Windows taskkill popups during process cleanup (#569)

This commit is contained in:
junes
2026-05-06 05:40:33 +08:00
committed by GitHub
parent 136badb86e
commit 23c0fa4872
+17 -2
View File
@@ -17,16 +17,31 @@ export function isProcessAlive(pid: number): boolean {
}
function killProcessWindows(pid: number, force: boolean): boolean {
if (!isProcessAlive(pid)) {
return true;
}
const args = ['/T', '/PID', pid.toString()];
if (force) {
args.unshift('/F');
}
try {
const result = spawn.sync('taskkill', args, { stdio: 'pipe' });
const result = spawn.sync('taskkill', args, {
stdio: 'pipe',
windowsHide: true
});
if (result.error) {
return false;
}
return result.status === 0;
if (result.status === 0) {
return true;
}
// Process teardown on Windows is racy: by the time taskkill runs, the target
// may already be gone, which commonly surfaces as non-zero exit codes
// (including 128 in some shells). Treat this as success if PID is no longer alive.
return !isProcessAlive(pid);
} catch {
return false;
}