MCPcopy Index your code
hub / github.com/nodejs/node / execFile

Function execFile

lib/child_process.js:326–525  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

324 * @returns {ChildProcess}
325 */
326function 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);

Calls 12

normalizeExecFileArgsFunction · 0.85
validateMaxBufferFunction · 0.85
sanitizeKillSignalFunction · 0.85
validateTimeoutFunction · 0.70
spawnFunction · 0.70
setTimeoutFunction · 0.70
killFunction · 0.70
sliceMethod · 0.65
sliceFunction · 0.50
setEncodingMethod · 0.45
onMethod · 0.45
addListenerMethod · 0.45

Tested by 1

testFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…