* Spawns the specified file as a shell. * @param {string} file * @param {string[]} [args] * @param {{ * cwd?: string | URL; * env?: Record ; * encoding?: string; * timeout?: number; * maxBuffer?: number; * killSignal?: string | number; * uid?: number; * gid?
(file, args, options, callback)
| 324 | * @returns {ChildProcess} |
| 325 | */ |
| 326 | function execFile(file, args, options, callback) { |
| 327 | ({ file, args, options, callback } = normalizeExecFileArgs(file, args, options, callback)); |
| 328 | |
| 329 | options = { |
| 330 | __proto__: null, |
| 331 | encoding: 'utf8', |
| 332 | timeout: 0, |
| 333 | maxBuffer: MAX_BUFFER, |
| 334 | killSignal: 'SIGTERM', |
| 335 | cwd: null, |
| 336 | env: null, |
| 337 | shell: false, |
| 338 | ...options, |
| 339 | }; |
| 340 | |
| 341 | // Validate the timeout, if present. |
| 342 | validateTimeout(options.timeout); |
| 343 | |
| 344 | // Validate maxBuffer, if present. |
| 345 | validateMaxBuffer(options.maxBuffer); |
| 346 | |
| 347 | options.killSignal = sanitizeKillSignal(options.killSignal); |
| 348 | |
| 349 | const child = spawn(file, args, { |
| 350 | cwd: options.cwd, |
| 351 | env: options.env, |
| 352 | gid: options.gid, |
| 353 | shell: options.shell, |
| 354 | signal: options.signal, |
| 355 | uid: options.uid, |
| 356 | windowsHide: !!options.windowsHide, |
| 357 | windowsVerbatimArguments: !!options.windowsVerbatimArguments, |
| 358 | }); |
| 359 | |
| 360 | let encoding; |
| 361 | const _stdout = []; |
| 362 | const _stderr = []; |
| 363 | if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) { |
| 364 | encoding = options.encoding; |
| 365 | } else { |
| 366 | encoding = null; |
| 367 | } |
| 368 | let stdoutLen = 0; |
| 369 | let stderrLen = 0; |
| 370 | let killed = false; |
| 371 | let exited = false; |
| 372 | let timeoutId; |
| 373 | |
| 374 | let ex = null; |
| 375 | |
| 376 | let cmd = file; |
| 377 | |
| 378 | function exithandler(code, signal) { |
| 379 | if (exited) return; |
| 380 | exited = true; |
| 381 | |
| 382 | if (timeoutId) { |
| 383 | clearTimeout(timeoutId); |
searching dependent graphs…