@@ -280,7 +280,7 @@ changes:
280280 ` '/bin/sh' ` on Unix, and ` process.env.ComSpec ` on Windows. A different
281281 shell can be specified as a string. See [ Shell requirements] [ ] and
282282 [ Default Windows shell] [ ] . ** Default:** ` false ` (no shell).
283- * ` signal ` {AbortSignal} allows aborting the execFile using an AbortSignal
283+ * ` signal ` {AbortSignal} allows aborting the execFile using an AbortSignal.
284284* ` callback ` {Function} Called with the output when process terminates.
285285 * ` error ` {Error}
286286 * ` stdout ` {string|Buffer}
@@ -344,7 +344,7 @@ const { signal } = controller;
344344const child = execFile (' node' , [' --version' ], { signal }, (error ) => {
345345 console .log (error); // an AbortError
346346});
347- signal .abort ();
347+ controller .abort ();
348348```
349349
350350### ` child_process.fork(modulePath[, args][, options]) `
@@ -424,6 +424,9 @@ The `shell` option available in [`child_process.spawn()`][] is not supported by
424424<!-- YAML
425425added: v0.1.90
426426changes:
427+ - version: REPLACEME
428+ pr-url: https://github.com/nodejs/node/pull/36432
429+ description: AbortSignal support was added.
427430 - version:
428431 - v13.2.0
429432 - v12.16.0
@@ -466,6 +469,8 @@ changes:
466469 when ` shell ` is specified and is CMD. ** Default:** ` false ` .
467470 * ` windowsHide ` {boolean} Hide the subprocess console window that would
468471 normally be created on Windows systems. ** Default:** ` false ` .
472+ * ` signal ` {AbortSignal} allows aborting the execFile using an AbortSignal.
473+
469474* Returns: {ChildProcess}
470475
471476The ` child_process.spawn() ` method spawns a new process using the given
@@ -572,6 +577,20 @@ Node.js currently overwrites `argv[0]` with `process.execPath` on startup, so
572577parameter passed to ` spawn ` from the parent, retrieve it with the
573578` process.argv0 ` property instead.
574579
580+ If the ` signal ` option is enabled, calling ` .abort() ` on the corresponding
581+ ` AbortController ` is similar to calling ` .kill() ` on the child process except
582+ the error passed to the callback will be an ` AbortError ` :
583+
584+ ``` js
585+ const controller = new AbortController ();
586+ const { signal } = controller;
587+ const grep = spawn (' grep' , [' ssh' ], { signal });
588+ grep .on (' error' , (err ) => {
589+ // This will be called with err being an AbortError if the controller aborts
590+ });
591+ controller .abort (); // stops the process
592+ ```
593+
575594#### ` options.detached `
576595<!-- YAML
577596added: v0.7.10
0 commit comments