| 523 | } |
| 524 | |
| 525 | export async function killProcess(pid) { |
| 526 | await new Promise<void>((resolve, reject) => { |
| 527 | treeKill(pid, (err) => { |
| 528 | if (err) { |
| 529 | if ( |
| 530 | process.platform === "win32" && |
| 531 | typeof err.message === "string" && |
| 532 | (err.message.includes(`no running instance of the task`) || |
| 533 | err.message.includes(`not found`)) |
| 534 | ) { |
| 535 | // Windows throws an error if the process is already dead |
| 536 | // |
| 537 | // Command failed: taskkill /pid 6924 /T /F |
| 538 | // ERROR: The process with PID 6924 (child process of PID 6736) could not be terminated. |
| 539 | // Reason: There is no running instance of the task. |
| 540 | return resolve() |
| 541 | } |
| 542 | return reject(err) |
| 543 | } |
| 544 | |
| 545 | resolve() |
| 546 | }) |
| 547 | }) |
| 548 | } |
| 549 | |
| 550 | // Kill a launched app |
| 551 | export async function killApp(instance) { |