| 293 | }; |
| 294 | |
| 295 | export function plainExec(defaultCwd: string | undefined): ExecFunction { |
| 296 | return async function (params: ExecParameters): Promise<Exec> { |
| 297 | const { cmd, args, stdio, output } = params; |
| 298 | |
| 299 | const text = `Run: ${cmd} ${(args || []).join(' ').replace(/\n.*/g, '')}`; |
| 300 | const start = output.start(text); |
| 301 | |
| 302 | const cwd = params.cwd || defaultCwd; |
| 303 | const env = params.env ? { ...process.env, ...params.env } : process.env; |
| 304 | const exec = await findLocalWindowsExecutable(cmd, cwd, env, output); |
| 305 | const p = cp.spawn(exec, args, { cwd, env, stdio: stdio as any, windowsHide: true }); |
| 306 | |
| 307 | return { |
| 308 | stdin: p.stdin, |
| 309 | stdout: p.stdout, |
| 310 | stderr: p.stderr, |
| 311 | exit: new Promise((resolve, reject) => { |
| 312 | p.once('error', err => { |
| 313 | output.stop(text, start); |
| 314 | reject(err); |
| 315 | }); |
| 316 | p.once('close', (code, signal) => { |
| 317 | output.stop(text, start); |
| 318 | resolve({ code, signal }); |
| 319 | }); |
| 320 | }), |
| 321 | async terminate() { |
| 322 | p.kill('SIGKILL'); |
| 323 | } |
| 324 | }; |
| 325 | }; |
| 326 | } |
| 327 | |
| 328 | export async function plainPtyExec(defaultCwd: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<PtyExecFunction> { |
| 329 | const pty = await loadNativeModule<typeof ptyType>('node-pty'); |