(command: string, args?: ReadonlyArray<string>, options?: cp.CommonOptions, onDisposed?: () => unknown)
| 487 | |
| 488 | export type DisposableProcess = cp.ChildProcessWithoutNullStreams & vscode.Disposable; |
| 489 | export function spawn(command: string, args?: ReadonlyArray<string>, options?: cp.CommonOptions, onDisposed?: () => unknown): DisposableProcess { |
| 490 | const proc = cp.spawn(command, args, options); |
| 491 | console.log(proc.pid ? `Process ${proc.pid} spawned` : 'Process failed to spawn'); |
| 492 | let running = true; |
| 493 | const exitHandler = () => { |
| 494 | running = false; |
| 495 | console.log(`Process ${proc.pid || ''} exited`); |
| 496 | }; |
| 497 | proc.on('exit', exitHandler); |
| 498 | proc.on('error', exitHandler); |
| 499 | const disposable = asDisposable(proc, () => { |
| 500 | if (running) { |
| 501 | console.log(`Process ${proc.pid || ''} terminating`); |
| 502 | if (process.platform === 'win32') { |
| 503 | if (proc.pid !== undefined) { |
| 504 | cp.spawnSync('taskkill', ['/pid', proc.pid.toString(), '/f', '/t']); |
| 505 | } |
| 506 | } else { |
| 507 | proc.kill('SIGKILL'); |
| 508 | } |
| 509 | } |
| 510 | if (onDisposed) { |
| 511 | onDisposed(); |
| 512 | } |
| 513 | }); |
| 514 | return disposable; |
| 515 | } |
| 516 | |
| 517 | export async function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: cp.CommonOptions, onDisposed?: () => unknown): Promise<cp.SpawnSyncReturns<string>> { |
| 518 | return new Promise((resolve) => { |
no test coverage detected