Skip to content
Myr

Improve headers in `readme.md` (#967)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent fdffcb6 · Browse files · 4 files+218 added−218 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+218 added−218 removed

  • other:+218 added−218 removed

4 files+218 added−218 removed

modified:docs/scripts.md+4 added-4 removed
3 unmodified lines
4 - [performant](#performance)5 - [cross-platform](#shell): [no shell](../readme.md#shell-syntax) is used, only JavaScript.6 - [secure](#escaping): no shell injection.7 - [simple](#simplicity): minimalistic API, no [globals](#global-variables), no [binary](#main-binary), no [builtin CLI utilities](#builtin-utilities).8 - [featureful](#simplicity): all Execa features are available ([subprocess piping](#piping-stdout-to-another-command), [IPC](#ipc), [transforms](#transforms), [background subprocesses](#background-subprocesses), [cancellation](#cancellation), [local binaries](#local-binaries), [cleanup on exit](../readme.md#cleanup), [interleaved output](#interleaved-output), [forceful termination](../readme.md#forcekillafterdelay), etc.).8 - [featureful](#simplicity): all Execa features are available ([subprocess piping](#piping-stdout-to-another-command), [IPC](#ipc), [transforms](#transforms), [background subprocesses](#background-subprocesses), [cancellation](#cancellation), [local binaries](#local-binaries), [cleanup on exit](../readme.md#optionscleanup), [interleaved output](#interleaved-output), [forceful termination](../readme.md#optionsforcekillafterdelay), etc.).9 - [easy to debug](#debugging): [verbose mode](#verbose-mode), [detailed errors](#errors), [messages and stack traces](#cancellation), stateless API.1011```js12import {$} from 'execa';
803 unmodified lines
816This is more cross-platform. For example, your code works the same on Windows machines without Bash installed.817818Also, there is no shell syntax to remember: everything is just plain JavaScript.819820If you really need a shell though, the [`shell` option](../readme.md#shell) can be used.820If you really need a shell though, the [`shell`](../readme.md#optionsshell) option can be used.821822### Simplicity823824Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#file-arguments-options) and [`$(options)`](../readme.md#execaoptions).
15 unmodified lines
840Also, [local binaries](#local-binaries) can be directly executed without using `npx`.841842### Debugging843844Subprocesses can be hard to debug, which is why Execa includes a [`verbose` option](#verbose-mode).844Subprocesses can be hard to debug, which is why Execa includes a [`verbose`](#verbose-mode) option.845846Also, Execa's error messages and [properties](#errors) are very detailed to make it clear to determine why a subprocess failed. Error messages and stack traces can be set with [`subprocess.kill(error)`](../readme.md#killerror).846Also, Execa's error messages and [properties](#errors) are very detailed to make it clear to determine why a subprocess failed. Error messages and stack traces can be set with [`subprocess.kill(error)`](../readme.md#subprocesskillerror).847848Finally, unlike Bash and zx, which are stateful (options, current directory, etc.), Execa is [purely functional](#current-directory), which also helps with debugging.
modified:docs/transform.md+6 added-6 removed
1# Transforms23## Summary45Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) to the [`stdin`](../readme.md#stdin), [`stdout`](../readme.md#stdout-1), [`stderr`](../readme.md#stderr-1) or [`stdio`](../readme.md#stdio-1) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).5Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) to the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) or [`stdio`](../readme.md#optionsstdio) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).67```js8import {execa} from 'execa';9
8 unmodified lines
1819## Encoding2021The `line` argument passed to the transform is a string by default.\22However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding` option](../readme.md#encoding) is binary, it is an `Uint8Array` instead.22However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding`](../readme.md#optionsencoding) option is binary, it is an `Uint8Array` instead.2324The transform can `yield` either a `string` or an `Uint8Array`, regardless of the `line` argument's type.2526## Filtering
15 unmodified lines
4243## Binary data4445The transform iterates over lines by default.\46However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding` option](../readme.md#encoding) is binary, it iterates over arbitrary chunks of data instead.46However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding`](../readme.md#optionsencoding) option is binary, it iterates over arbitrary chunks of data instead.4748```js49await execa('./binary.js', {stdout: {transform, binary: true}});50```
64 unmodified lines
115116## Object mode117118By default, `stdout` and `stderr`'s transforms must return a string or an `Uint8Array`.\119However, if a `{transform, objectMode: true}` plain object is passed, any type can be returned instead, except `null` or `undefined`. The subprocess' [`stdout`](../readme.md#stdout)/[`stderr`](../readme.md#stderr) will be an array of values.119However, if a `{transform, objectMode: true}` plain object is passed, any type can be returned instead, except `null` or `undefined`. The subprocess' [`stdout`](../readme.md#resultstdout)/[`stderr`](../readme.md#resultstderr) will be an array of values.120121```js122const transform = function * (line) {123 yield JSON.parse(line);
73 unmodified lines
197```198199## Combining200201The [`stdin`](../readme.md#stdin), [`stdout`](../readme.md#stdout-1), [`stderr`](../readme.md#stderr-1) and [`stdio`](../readme.md#stdio-1) options can accept an array of values. While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `inherit`.201The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and [`stdio`](../readme.md#optionsstdio) options can accept an array of values. While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `inherit`.202203```js204await execa('echo', ['hello'], {stdout: [transform, 'inherit']});205```
11 unmodified lines
217```218219## Async iteration220221In some cases, [iterating](../readme.md#iterablereadableoptions) over the subprocess can be an alternative to transforms.221In some cases, [iterating](../readme.md#subprocessiterablereadableoptions) over the subprocess can be an alternative to transforms.222223```js224import {execa} from 'execa';225
5 unmodified lines
modified:index.d.ts+27 added-27 removed
440 unmodified lines
441 readonly stdin?: StdinOptionCommon<IsSync>;442443 /**444 [How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:445 - `'pipe'`: Sets `subprocessResult.stdout` (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).445 - `'pipe'`: Sets `result.stdout` (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).446 - `'overlapped'`: Like `'pipe'` but asynchronous on Windows.447 - `'ignore'`: Do not use `stdout`.448 - `'inherit'`: Re-use the current process' `stdout`.449 - an integer: Re-use a specific file descriptor from the current process.
11 unmodified lines
461 readonly stdout?: StdoutStderrOptionCommon<IsSync>;462463 /**464 [How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:465 - `'pipe'`: Sets `subprocessResult.stderr` (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).465 - `'pipe'`: Sets `result.stderr` (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).466 - `'overlapped'`: Like `'pipe'` but asynchronous on Windows.467 - `'ignore'`: Do not use `stderr`.468 - `'inherit'`: Re-use the current process' `stderr`.469 - an integer: Re-use a specific file descriptor from the current process.
215 unmodified lines
685 */686 readonly buffer?: boolean;687688 /**689 Add an `.all` property on the promise and the resolved value. The property contains the output of the subprocess with `stdout` and `stderr` interleaved.689 Add a `subprocess.all` stream and a `result.all` property. They contain the combined/[interleaved](#ensuring-all-output-is-interleaved) output of the subprocess' `stdout` and `stderr`.690691 @default false692 */693 readonly all?: boolean;
25 unmodified lines
719720 /**721 You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).722723 When `AbortController.abort()` is called, `.isCanceled` becomes `true`.723 When `AbortController.abort()` is called, `result.isCanceled` becomes `true`.724725 @example726 ```727 import {execa} from 'execa';
159 unmodified lines
887888 /**889 Results of the other subprocesses that were piped into this subprocess. This is useful to inspect a series of subprocesses piped with each other.890891 This array is initially empty and is populated each time the `.pipe()` method resolves.891 This array is initially empty and is populated each time the `subprocess.pipe()` method resolves.892 */893 pipedFrom: Unless<IsSync, ExecaResult[], []>;894895 /**
15 unmodified lines
911 */912 originalMessage?: string;913914 /**915 Underlying error, if there is one. For example, this is set by `.kill(error)`.915 Underlying error, if there is one. For example, this is set by `subprocess.kill(error)`.916917 This is usually an `Error` instance.918 */919 cause?: unknown;
58 unmodified lines
978979/**980Exception thrown when the subprocess fails, either:981- its exit code is not `0`982- it was terminated with a signal, including `.kill()`982- it was terminated with a signal, including `subprocess.kill()`983- timing out984- being canceled985- there's not enough memory or there are already too many subprocesses986
73 unmodified lines
10601061 /**1062 Unpipe the subprocess when the signal aborts.10631064 The `.pipe()` method will be rejected with a cancellation error.1064 The `subprocess.pipe()` method will be rejected with a cancellation error.1065 */1066 readonly unpipeSignal?: AbortSignal;1067};1068
17 unmodified lines
1086 options?: OptionsType,1087 ): Promise<ExecaResult<OptionsType>> & PipableSubprocess;10881089 /**1090 Like `.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.1090 Like `subprocess.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.1091 */1092 pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):1093 Promise<ExecaResult<{}>> & PipableSubprocess;1094 pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):1095 (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[])1096 => Promise<ExecaResult<OptionsType>> & PipableSubprocess;10971098 /**1099 Like `.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.1099 Like `subprocess.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.11001101 This is the most advanced method to pipe subprocesses. It is useful in specific cases, such as piping multiple subprocesses to the same subprocess.1102 */1103 pipe<Destination extends ExecaSubprocess>(destination: Destination, options?: PipeOptions):
12 unmodified lines
11161117 /**1118 If `false`, the stream iterates over lines. Each line is a string. Also, the stream is in [object mode](https://nodejs.org/api/stream.html#object-mode).11191120 If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with `.iterable()`) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).1120 If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with `subprocess.iterable()`) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).11211122 This is always `true` when the `encoding` option is binary.11231124 @default `false` with `.iterable()`, `true` otherwise1124 @default `false` with `subprocess.iterable()`, `true` otherwise1125 */1126 readonly binary?: boolean;11271128 /**1129 If both this option and the `binary` option is `false`, newlines are stripped from each line.11301131 @default `false` with `.iterable()`, `true` otherwise1131 @default `false` with `subprocess.iterable()`, `true` otherwise1132 */1133 readonly preserveNewlines?: boolean;1134};1135
135 unmodified lines
12711272@param file - The program/script to execute, as a string or file URL1273@param arguments - Arguments to pass to `file` on execution.1274@returns An `ExecaSubprocess` that is both:1275- a `Promise` resolving or rejecting with a `subprocessResult`.1275- a `Promise` resolving or rejecting with a subprocess `result`.1276- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.1277@throws A `subprocessResult` error1277@throws A subprocess `result` error12781279@example <caption>Promise interface</caption>1280```1281import {execa} from 'execa';
173 unmodified lines
14551456/**1457Same as `execa()` but synchronous.14581459Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available.1459Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.14601461The following features cannot be used:1462- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1463- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.
6 unmodified lines
1470- The `maxBuffer` option is always measured in bytes, not in characters, lines nor objects. Also, it ignores transforms and the `encoding` option.14711472@param file - The program/script to execute, as a string or file URL1473@param arguments - Arguments to pass to `file` on execution.1474@returns A `subprocessResult` object1475@throws A `subprocessResult` error1474@returns A subprocess `result` object1475@throws A subprocess `result` error14761477@example <caption>Promise interface</caption>1478```1479import {execa} from 'execa';
70 unmodified lines
1550Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.15511552@param command - The program/script to execute and its arguments.1553@returns An `ExecaSubprocess` that is both:1554- a `Promise` resolving or rejecting with a `subprocessResult`.1554- a `Promise` resolving or rejecting with a subprocess `result`.1555- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.1556@throws A `subprocessResult` error1556@throws A subprocess `result` error15571558@example1559```1560import {execaCommand} from 'execa';
18 unmodified lines
15791580/**1581Same as `execaCommand()` but synchronous.15821583Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available.1583Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.15841585The following features cannot be used:1586- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1587- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.
5 unmodified lines
1593- `detached` option.1594- The `maxBuffer` option is always measured in bytes, not in characters, lines nor objects. Also, it ignores transforms and the `encoding` option.15951596@param command - The program/script to execute and its arguments.1597@returns A `subprocessResult` object1598@throws A `subprocessResult` error1597@returns A subprocess `result` object1598@throws A subprocess `result` error15991600@example1601```1602import {execaCommandSync} from 'execa';
51 unmodified lines
16541655This is the preferred method when executing multiple commands in a script file.16561657@returns An `ExecaSubprocess` that is both:1658 - a `Promise` resolving or rejecting with a `subprocessResult`.1658 - a `Promise` resolving or rejecting with a subprocess `result`.1659 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.1660@throws A `subprocessResult` error1660@throws A subprocess `result` error16611662@example <caption>Basic</caption>1663```1664import {$} from 'execa';
46 unmodified lines
17111712@param scriptPath - Node.js script to execute, as a string or file URL1713@param arguments - Arguments to pass to `scriptPath` on execution.1714@returns An `ExecaSubprocess` that is both:1715- a `Promise` resolving or rejecting with a `subprocessResult`.1715- a `Promise` resolving or rejecting with a subprocess `result`.1716- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.1717@throws A `subprocessResult` error1717@throws A subprocess `result` error17181719@example1720```1721import {execaNode} from 'execa';
5 unmodified lines
modified:readme.md+181 added-181 removed
48 unmodified lines
4950- [Promise interface](#execafile-arguments-options).51- [Script interface](docs/scripts.md) and [template strings](#template-string-syntax), like `zx`.52- Improved [Windows support](https://github.com/IndigoUnited/node-cross-spawn#why), including [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries.53- Executes [locally installed binaries](#preferlocal) without `npx`.54- [Cleans up](#cleanup) subprocesses when the current process ends.55- Redirect [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1) from/to files, streams, iterables, strings, `Uint8Array` or [objects](docs/transform.md#object-mode).53- Executes [locally installed binaries](#optionspreferlocal) without `npx`.54- [Cleans up](#optionscleanup) subprocesses when the current process ends.55- Redirect [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr) from/to files, streams, iterables, strings, `Uint8Array` or [objects](docs/transform.md#object-mode).56- [Transform](docs/transform.md) `stdin`/`stdout`/`stderr` with simple functions.57- Iterate over [each text line](docs/transform.md#binary-data) output by the subprocess.58- [Fail-safe subprocess termination](#forcekillafterdelay).59- Get [interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal.60- [Strips the final newline](#stripfinalnewline) from the output so you don't have to do `stdout.trim()`.61- Convenience methods to pipe subprocesses' [input](#input) and [output](#redirect-output-to-a-file).58- [Fail-safe subprocess termination](#optionsforcekillafterdelay).59- Get [interleaved output](#optionsall) from `stdout` and `stderr` similar to what is printed on the terminal.60- [Strips the final newline](#optionsstripfinalnewline) from the output so you don't have to do `stdout.trim()`.61- Convenience methods to pipe subprocesses' [input](#redirect-input-from-a-file) and [output](#redirect-output-to-a-file).62- [Verbose mode](#verbose-mode) for debugging.63- More descriptive errors.64- Higher max buffer: 100 MB instead of 1 MB.65
231 unmodified lines
297_Returns_: [`Subprocess`](#subprocess)298299Executes a command. `command` is a [template string](#template-string-syntax) and includes both the `file` and its `arguments`.300301The `command` template string can inject any `${value}` with the following types: string, number, [`subprocess`](#subprocess) or an array of those types. For example: `` execa`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's [`stdout`](#stdout) is used.301The `command` template string can inject any `${value}` with the following types: string, number, [`subprocess`](#subprocess) or an array of those types. For example: `` execa`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's [`stdout`](#resultstdout) is used.302303Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces, tabs and newlines must use `${}` like `` execa`echo ${'has space'}` ``.304305The `command` template string can use [multiple lines and indentation](docs/scripts.md#multiline-commands).
11 unmodified lines
317#### execaSync\`command\`318319Same as [`execa()`](#execafile-arguments-options) but synchronous.320321Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.321Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.322323The following features cannot be used:324- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.readable()`](#readablereadableoptions), [`subprocess.writable()`](#writablewritableoptions), [`subprocess.duplex()`](#duplexduplexoptions).325- The [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.326- Signal termination: [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`subprocess.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`cleanup`](#cleanup) option, [`cancelSignal`](#cancelsignal) option, [`forceKillAfterDelay`](#forcekillafterdelay) option.327- Piping multiple processes: [`subprocess.pipe()`](#pipefile-arguments-options).328- [`subprocess.iterable()`](#iterablereadableoptions).329- [`ipc`](#ipc) and [`serialization`](#serialization) options.330- [`result.all`](#all-1) is not interleaved.331- [`detached`](#detached) option.332- The [`maxBuffer`](#maxbuffer) option is always measured in bytes, not in characters, [lines](#lines) nor [objects](docs/transform.md#object-mode). Also, it ignores transforms and the [`encoding`](#encoding) option.324- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.readable()`](#subprocessreadablereadableoptions), [`subprocess.writable()`](#subprocesswritablewritableoptions), [`subprocess.duplex()`](#subprocessduplexduplexoptions).325- The [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [`stdio`](#optionsstdio) options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.326- Signal termination: [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`subprocess.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`cleanup`](#optionscleanup) option, [`cancelSignal`](#optionscancelsignal) option, [`forceKillAfterDelay`](#optionsforcekillafterdelay) option.327- Piping multiple processes: [`subprocess.pipe()`](#subprocesspipefile-arguments-options).328- [`subprocess.iterable()`](#subprocessiterablereadableoptions).329- [`ipc`](#optionsipc) and [`serialization`](#optionsserialization) options.330- [`result.all`](#resultall) is not interleaved.331- [`detached`](#optionsdetached) option.332- The [`maxBuffer`](#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](#optionslines) nor [objects](docs/transform.md#object-mode). Also, it ignores transforms and the [`encoding`](#optionsencoding) option.333334#### $(file, arguments?, options?)335336`file`: `string | URL`\337`arguments`: `string[]`\338`options`: [`Options`](#options)\339_Returns_: [`Subprocess`](#subprocess)340341Same as [`execa()`](#execafile-arguments-options) but using the [`stdin: 'inherit'`](#stdin) and [`preferLocal: true`](#preferlocal) options.341Same as [`execa()`](#execafile-arguments-options) but using the [`stdin: 'inherit'`](#optionsstdin) and [`preferLocal: true`](#optionspreferlocal) options.342343Just like `execa()`, this can use the [template string syntax](#execacommand) or [bind options](#execaoptions). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.344345This is the preferred method when executing multiple commands in a script file. For more information, please see [this page](docs/scripts.md).
4 unmodified lines
350`arguments`: `string[]`\351`options`: [`Options`](#options)\352_Returns_: [`Subprocess`](#subprocess)353354Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#node) option.354Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.355Executes a Node.js file using `node scriptPath ...arguments`.356357Just like `execa()`, this can use the [template string syntax](#execacommand) or [bind options](#execaoptions).358
14 unmodified lines
373Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.374375### Shell syntax376377For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.377For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell`](#optionsshell) option is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.378379### subprocess380381The return value of all [asynchronous methods](#methods) is both:382- a `Promise` resolving or rejecting with a [`subprocessResult`](#subprocessResult).382- a `Promise` resolving or rejecting with a subprocess [`result`](#result).383- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties.384385#### all385#### subprocess.all386387Type: `ReadableStream | undefined`388389Stream [combining/interleaving](#ensuring-all-output-is-interleaved) [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).390391This is `undefined` if either:392- the [`all` option](#all-2) is `false` (the default value)393- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)392- the [`all`](#optionsall) option is `false` (the default value)393- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)394395#### pipe(file, arguments?, options?)395#### subprocess.pipe(file, arguments?, options?)396397`file`: `string | URL`\398`arguments`: `string[]`\399`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\400_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)400_Returns_: [`Promise<Result>`](#result)401402[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' `stdout` to a second Execa subprocess' `stdin`. This resolves with that second subprocess' [result](#subprocessresult). If either subprocess is rejected, this is rejected with that subprocess' [error](#execaerror) instead.402[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' `stdout` to a second Execa subprocess' `stdin`. This resolves with that second subprocess' [result](#result). If either subprocess is rejected, this is rejected with that subprocess' [error](#execaerror) instead.403404This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options) and [pipe-specific options](#pipeoptions) can be specified.405406This can be called multiple times to chain a series of subprocesses.407408Multiple subprocesses can be piped to the same subprocess. Conversely, the same subprocess can be piped to multiple other subprocesses.409410#### pipe\`command\`411#### pipe(options)\`command\`410#### subprocess.pipe\`command\`411#### subprocess.pipe(options)\`command\`412413`command`: `string`\414`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\415_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)415_Returns_: [`Promise<Result>`](#result)416417Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](#execacommand).417Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](#execacommand).418419#### pipe(secondSubprocess, pipeOptions?)419#### subprocess.pipe(secondSubprocess, pipeOptions?)420421`secondSubprocess`: [`execa()` return value](#subprocess)\422`pipeOptions`: [`PipeOptions`](#pipeoptions)\423_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)423_Returns_: [`Promise<Result>`](#result)424425Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using the [return value](#subprocess) of another `execa()` call instead.425Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#subprocess) of another `execa()` call instead.426427This is the most advanced method to pipe subprocesses. It is useful in specific cases, such as piping multiple subprocesses to the same subprocess.428429##### pipeOptions
6 unmodified lines
436Default: `"stdout"`437438Which stream to pipe from the source subprocess. A file descriptor like `"fd3"` can also be passed.439440`"all"` pipes both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.440`"all"` pipes both `stdout` and `stderr`. This requires the [`all`](#optionsall) option to be `true`.441442##### pipeOptions.to443444Type: `"stdin" | "fd3" | "fd4" | ...`\
6 unmodified lines
451Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)452453Unpipe the subprocess when the signal aborts.454455The [`.pipe()`](#pipefile-arguments-options) method will be rejected with a cancellation error.455The [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method will be rejected with a cancellation error.456457#### kill(signal, error?)458#### kill(error?)457#### subprocess.kill(signal, error?)458#### subprocess.kill(error?)459460`signal`: `string | number`\461`error`: `Error`\462_Returns_: `boolean`463464Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#killsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#isterminated) the subprocess.464Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#optionskillsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#resultisterminated) the subprocess.465466This returns `false` when the signal could not be sent, for example when the subprocess has already exited.467468When an error is passed as argument, it is set to the subprocess' [`error.cause`](#cause). The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).468When an error is passed as argument, it is set to the subprocess' [`error.cause`](#errorcause). The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).469470[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)471472#### [Symbol.asyncIterator]()472#### subprocess[Symbol.asyncIterator]()473474_Returns_: `AsyncIterable`475476Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.477478The iteration waits for the subprocess to end. It throws if the subprocess [fails](#subprocessresult). This means you do not need to `await` the subprocess' [promise](#subprocess).478The iteration waits for the subprocess to end. It throws if the subprocess [fails](#result). This means you do not need to `await` the subprocess' [promise](#subprocess).479480#### iterable(readableOptions?)480#### subprocess.iterable(readableOptions?)481482`readableOptions`: [`ReadableOptions`](#readableoptions)\483_Returns_: `AsyncIterable`484485Same as [`subprocess[Symbol.asyncIterator]`](#symbolasynciterator) except [options](#readableoptions) can be provided.485Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.486487#### readable(readableOptions?)487#### subprocess.readable(readableOptions?)488489`readableOptions`: [`ReadableOptions`](#readableoptions)\490_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream491492Converts the subprocess to a readable stream.493494Unlike [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), the stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#subprocessresult). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options), [`await pipeline(..., stream)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) or [`await text(stream)`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) which throw an exception when the stream errors.494Unlike [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), the stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options), [`await pipeline(..., stream)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) or [`await text(stream)`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) which throw an exception when the stream errors.495496Before using this method, please first consider the [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1)/[`stdio`](#stdio-1) options, [`subprocess.pipe()`](#pipefile-arguments-options) or [`subprocess.iterable()`](#iterablereadableoptions).496Before using this method, please first consider the [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr)/[`stdio`](#optionsstdio) options, [`subprocess.pipe()`](#subprocesspipefile-arguments-options) or [`subprocess.iterable()`](#subprocessiterablereadableoptions).497498#### writable(writableOptions?)498#### subprocess.writable(writableOptions?)499500`writableOptions`: [`WritableOptions`](#writableoptions)\501_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream502503Converts the subprocess to a writable stream.504505Unlike [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), the stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#subprocessresult). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.505Unlike [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), the stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.506507Before using this method, please first consider the [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1)/[`stdio`](#stdio-1) options or [`subprocess.pipe()`](#pipefile-arguments-options).507Before using this method, please first consider the [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr)/[`stdio`](#optionsstdio) options or [`subprocess.pipe()`](#subprocesspipefile-arguments-options).508509#### duplex(duplexOptions?)509#### subprocess.duplex(duplexOptions?)510511`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\512_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream513514Converts the subprocess to a duplex stream.515516The stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#subprocessresult). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options), [`await pipeline(..., stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) or [`await text(stream)`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) which throw an exception when the stream errors.516The stream waits for the subprocess to end and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options), [`await pipeline(..., stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) or [`await text(stream)`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) which throw an exception when the stream errors.517518Before using this method, please first consider the [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1)/[`stdio`](#stdio-1) options, [`subprocess.pipe()`](#pipefile-arguments-options) or [`subprocess.iterable()`](#iterablereadableoptions).518Before using this method, please first consider the [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr)/[`stdio`](#optionsstdio) options, [`subprocess.pipe()`](#subprocesspipefile-arguments-options) or [`subprocess.iterable()`](#subprocessiterablereadableoptions).519520##### readableOptions521522Type: `object`
4 unmodified lines
527Default: `"stdout"`528529Which stream to read from the subprocess. A file descriptor like `"fd3"` can also be passed.530531`"all"` reads both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.531`"all"` reads both `stdout` and `stderr`. This requires the [`all`](#optionsall) option to be `true`.532533##### readableOptions.binary534535Type: `boolean`\536Default: `false` with [`.iterable()`](#iterablereadableoptions), `true` with [`.readable()`](#readablereadableoptions)/[`.duplex()`](#duplexduplexoptions)536Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)537538If `false`, the stream iterates over lines. Each line is a string. Also, the stream is in [object mode](https://nodejs.org/api/stream.html#object-mode).539540If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with [`.iterable()`](#iterablereadableoptions)) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).540If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with [`subprocess.iterable()`](#subprocessiterablereadableoptions)) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).541542This is always `true` when the [`encoding` option](#encoding) is binary.542This is always `true` when the [`encoding`](#optionsencoding) option is binary.543544##### readableOptions.preserveNewlines545546Type: `boolean`\547Default: `false` with [`.iterable()`](#iterablereadableoptions), `true` with [`.readable()`](#readablereadableoptions)/[`.duplex()`](#duplexduplexoptions)547Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)548549If both this option and the [`binary` option](#readableoptionsbinary) is `false`, newlines are stripped from each line.549If both this option and the [`binary`](#readableoptionsbinary) option is `false`, newlines are stripped from each line.550551##### writableOptions552553Type: `object`
4 unmodified lines
558Default: `"stdin"`559560Which stream to write to the subprocess. A file descriptor like `"fd3"` can also be passed.561562### SubprocessResult562### Result563564Type: `object`565566Result of a subprocess execution.567568When the subprocess [fails](#failed), it is rejected with an [`ExecaError`](#execaerror) instead.568When the subprocess [fails](#resultfailed), it is rejected with an [`ExecaError`](#execaerror) instead.569570#### command570#### result.command571572Type: `string`573574The file and arguments that were run, for logging purposes.575576This is not escaped and should not be executed directly as a subprocess, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).577578#### escapedCommand578#### result.escapedCommand579580Type: `string`581582Same as [`command`](#command) but escaped.582Same as [`command`](#resultcommand) but escaped.583584Unlike `command`, control characters are escaped, which makes it safe to print in a terminal.585586This can also be copied and pasted into a shell, for debugging purposes.587Since the escaping is fairly basic, this should not be executed directly as a subprocess, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).588589#### cwd589#### result.cwd590591Type: `string`592593The [current directory](#cwd-1) in which the command was run.593The [current directory](#optionscwd) in which the command was run.594595#### durationMs595#### result.durationMs596597Type: `number`598599Duration of the subprocess, in milliseconds.600601#### stdout601#### result.stdout602603Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`604605The output of the subprocess on `stdout`.606607This is `undefined` if the [`stdout`](#stdout-1) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines` option](#lines) is `true`, or if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).607This is `undefined` if the [`stdout`](#optionsstdout) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines`](#optionslines) option is `true`, or if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).608609#### stderr609#### result.stderr610611Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`612613The output of the subprocess on `stderr`.614615This is `undefined` if the [`stderr`](#stderr-1) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines` option](#lines) is `true`, or if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).615This is `undefined` if the [`stderr`](#optionsstderr) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines`](#optionslines) option is `true`, or if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).616617#### all617#### result.all618619Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`620621The output of the subprocess with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).622623This is `undefined` if either:624- the [`all` option](#all-2) is `false` (the default value)625- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)624- the [`all`](#optionsall) option is `false` (the default value)625- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)626627This is an array if the [`lines` option](#lines) is `true`, or if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).627This is an array if the [`lines`](#optionslines) option is `true`, or if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).628629#### stdio629#### result.stdio630631Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`632633The output of the subprocess on [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [other file descriptors](#stdio-1).633The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).634635Items are `undefined` when their corresponding [`stdio`](#stdio-1) option is set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).635Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).636637#### failed637#### result.failed638639Type: `boolean`640641Whether the subprocess failed to run.642643#### timedOut643#### result.timedOut644645Type: `boolean`646647Whether the subprocess timed out.648649#### isCanceled649#### result.isCanceled650651Type: `boolean`652653Whether the subprocess was canceled using the [`cancelSignal`](#cancelsignal) option.653Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.654655#### isTerminated655#### result.isTerminated656657Type: `boolean`658659Whether the subprocess was terminated by a signal (like `SIGTERM`) sent by either:660- The current process.661- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).662663#### isMaxBuffer663#### result.isMaxBuffer664665Type: `boolean`666667Whether the subprocess failed because its output was larger than the [`maxBuffer`](#maxbuffer) option.667Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.668669#### exitCode669#### result.exitCode670671Type: `number | undefined`672673The numeric exit code of the subprocess that was run.674675This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#signal).675This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).676677#### signal677#### result.signal678679Type: `string | undefined`680681The name of the signal (like `SIGTERM`) that terminated the subprocess, sent by either:
1 unmodified line
683- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).684685If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`.686687#### signalDescription687#### result.signalDescription688689Type: `string | undefined`690691A human-friendly description of the signal that was used to terminate the subprocess. For example, `Floating point arithmetic error`.692693If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.694695#### pipedFrom695#### result.pipedFrom696697Type: [`Array<SubprocessResult | ExecaError>`](#subprocessresult)697Type: [`Array<Result | ExecaError>`](#result)698699Results of the other subprocesses that were [piped](#pipe-multiple-subprocesses) into this subprocess. This is useful to inspect a series of subprocesses piped with each other.700701This array is initially empty and is populated each time the [`.pipe()`](#pipefile-arguments-options) method resolves.701This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.702703### ExecaError704### ExecaSyncError705706Type: `Error`707708Exception thrown when the subprocess [fails](#failed), either:709- its [exit code](#exitcode) is not `0`710- it was [terminated](#isterminated) with a [signal](#signal), including [`.kill()`](#killerror)711- [timing out](#timedout)712- [being canceled](#iscanceled)708Exception thrown when the subprocess [fails](#resultfailed), either:709- its [exit code](#resultexitcode) is not `0`710- it was [terminated](#resultisterminated) with a [signal](#resultsignal), including [`subprocess.kill()`](#subprocesskillerror)711- [timing out](#resulttimedout)712- [being canceled](#resultiscanceled)713- there's not enough memory or there are already too many subprocesses714715This has the same shape as [successful results](#subprocessresult), with the following additional properties.715This has the same shape as [successful results](#result), with the following additional properties.716717#### message717#### error.message718719Type: `string`720721Error message when the subprocess failed to run. In addition to the [underlying error message](#originalMessage), it also contains some information related to why the subprocess errored.721Error message when the subprocess failed to run. In addition to the [underlying error message](#errororiginalmessage), it also contains some information related to why the subprocess errored.722723The subprocess [`stderr`](#stderr), [`stdout`](#stdout) and other [file descriptors' output](#stdio) are appended to the end, separated with newlines and not interleaved.723The subprocess [`stderr`](#resultstderr), [`stdout`](#resultstdout) and other [file descriptors' output](#resultstdio) are appended to the end, separated with newlines and not interleaved.724725#### shortMessage725#### error.shortMessage726727Type: `string`728729This is the same as the [`message` property](#message) except it does not include the subprocess [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio).729This is the same as the [`message` property](#errormessage) except it does not include the subprocess [`stdout`](#resultstdout)/[`stderr`](#resultstderr)/[`stdio`](#resultstdio).730731#### originalMessage731#### error.originalMessage732733Type: `string | undefined`734735Original error message. This is the same as the `message` property excluding the subprocess [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio) and some additional information added by Execa.735Original error message. This is the same as the `message` property excluding the subprocess [`stdout`](#resultstdout)/[`stderr`](#resultstderr)/[`stdio`](#resultstdio) and some additional information added by Execa.736737This exists only if the subprocess exited due to an `error` event or a timeout.738739#### cause739#### error.cause740741Type: `unknown | undefined`742743Underlying error, if there is one. For example, this is set by [`.kill(error)`](#killerror).743Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).744745This is usually an `Error` instance.746747#### code747#### error.code748749Type: `string | undefined`750751Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.
3 unmodified lines
755Type: `object`756757This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).758759Some options are related to the subprocess output: [`maxBuffer`](#maxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.759Some options are related to the subprocess output: [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.760761```js762await execa('./run.js', {maxBuffer: 1e6}) // Same value for stdout and stderr763await execa('./run.js', {maxBuffer: {stdout: 1e4, stderr: 1e6}}) // Different values764```765766#### reject766#### options.reject767768Type: `boolean`\769Default: `true`770771Setting this to `false` resolves the promise with the [error](#execaerror) instead of rejecting it.772773#### shell773#### options.shell774775Type: `boolean | string | URL`\776Default: `false`777
3 unmodified lines
781- not cross-platform, encouraging shell-specific syntax.782- slower, because of the additional shell interpretation.783- unsafe, potentially allowing command injection.784785#### cwd785#### options.cwd786787Type: `string | URL`\788Default: `process.cwd()`789790Current working directory of the subprocess.791792This is also used to resolve the [`nodePath`](#nodepath) option when it is a relative path.792This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.793794#### env794#### options.env795796Type: `object`\797Default: `process.env`798799Environment key-value pairs.800801Unless the [`extendEnv` option](#extendenv) is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).801Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).802803#### extendEnv803#### options.extendEnv804805Type: `boolean`\806Default: `true`807808If `true`, the subprocess uses both the [`env` option](#env) and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).808If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).809If `false`, only the `env` option is used, not `process.env`.810811#### preferLocal811#### options.preferLocal812813Type: `boolean`\814Default: `true` with [`$`](#file-arguments-options), `false` otherwise815816Prefer locally installed binaries when looking for a binary to execute.\817If you `$ npm install foo`, you can then `execa('foo')`.818819#### localDir819#### options.localDir820821Type: `string | URL`\822Default: `process.cwd()`823824Preferred path to find locally installed binaries in (use with `preferLocal`).825826#### node826#### options.node827828Type: `boolean`\829Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise830831If `true`, runs with Node.js. The first argument must be a Node.js file.832833#### nodeOptions833#### options.nodeOptions834835Type: `string[]`\836Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)837838List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#nodepath).838List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).839840Requires the [`node`](#node) option to be `true`.840Requires the [`node`](#optionsnode) option to be `true`.841842#### nodePath842#### options.nodePath843844Type: `string | URL`\845Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)846847Path to the Node.js executable.848849For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version.850851Requires the [`node`](#node) option to be `true`.851Requires the [`node`](#optionsnode) option to be `true`.852853#### verbose853#### options.verbose854855Type: `'none' | 'short' | 'full'`\856Default: `'none'`857858If `verbose` is `'short'` or `'full'`, [prints each command](#verbose-mode) on `stderr` before executing it. When the command completes, prints its duration and (if it failed) its error.859860If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:861- the [`stdout`](#stdout-1)/[`stderr`](#stderr-1) option is `ignore` or `inherit`.862- the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), [a file](#stdout-1), a file descriptor, or [another subprocess](#pipefile-arguments-options).863- the [`encoding` option](#encoding) is binary.861- the [`stdout`](#optionsstdout)/[`stderr`](#optionsstderr) option is `ignore` or `inherit`.862- the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), [a file](#optionsstdout), a file descriptor, or [another subprocess](#subprocesspipefile-arguments-options).863- the [`encoding`](#optionsencoding) option is binary.864865This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.866867#### buffer867#### options.buffer868869Type: `boolean`\870Default: `true`871872Whether to return the subprocess' output using the [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) properties.872Whether to return the subprocess' output using the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties.873874On failure, the [`error.stdout`](#stdout), [`error.stderr`](#stderr), [`error.all`](#all-1) and [`error.stdio`](#stdio) properties are used instead.874On failure, the [`error.stdout`](#resultstdout), [`error.stderr`](#resultstderr), [`error.all`](#resultall) and [`error.stdio`](#resultstdio) properties are used instead.875876When `buffer` is `false`, the output can still be read using the [`subprocess.stdout`](#stdout-1), [`subprocess.stderr`](#stderr-1), [`subprocess.stdio`](https://nodejs.org/api/child_process.html#subprocessstdio) and [`subprocess.all`](#all) streams. If the output is read, this should be done right away to avoid missing any data.876When `buffer` is `false`, the output can still be read using the [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.stdio`](https://nodejs.org/api/child_process.html#subprocessstdio) and [`subprocess.all`](#subprocessall) streams. If the output is read, this should be done right away to avoid missing any data.877878#### input878#### options.input879880Type: `string | Uint8Array | stream.Readable`881882Write some input to the subprocess' `stdin`.883884See also the [`inputFile`](#inputfile) and [`stdin`](#stdin) options.884See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.885886#### inputFile886#### options.inputFile887888Type: `string | URL`889890Use a file as input to the subprocess' `stdin`.891892See also the [`input`](#input) and [`stdin`](#stdin) options.892See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.893894#### stdin894#### options.stdin895896Type: `string | number | stream.Readable | ReadableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string | Uint8Array | unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\897Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise898
13 unmodified lines
912This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.913914This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)915916#### stdout916#### options.stdout917918Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\919Default: `pipe`920921[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:922- `'pipe'`: Sets [`subprocessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).922- `'pipe'`: Sets [`result.stdout`](#resultstdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).923- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.924- `'ignore'`: Do not use `stdout`.925- `'inherit'`: Re-use the current process' `stdout`.926- an integer: Re-use a specific file descriptor from the current process.
5 unmodified lines
932This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.933934This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)935936#### stderr936#### options.stderr937938Type: `string | number | stream.Writable | WritableStream | TransformStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}` (or a tuple of those types)\939Default: `pipe`940941[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:942- `'pipe'`: Sets [`subprocessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).942- `'pipe'`: Sets [`result.stderr`](#resultstderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).943- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.944- `'ignore'`: Do not use `stderr`.945- `'inherit'`: Re-use the current process' `stderr`.946- an integer: Re-use a specific file descriptor from the current process.
5 unmodified lines
952This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.953954This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)955956#### stdio956#### options.stdio957958Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\959Default: `pipe`960961Like the [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options but for all file descriptors at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.961Like the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options but for all file descriptors at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.962963A single string can be used as a shortcut. For example, `{stdio: 'pipe'}` is the same as `{stdin: 'pipe', stdout: 'pipe', stderr: 'pipe'}`.964965The array can have more than 3 items, to create additional file descriptors beyond `stdin`/`stdout`/`stderr`. For example, `{stdio: ['pipe', 'pipe', 'pipe', 'pipe']}` sets a fourth file descriptor.966967#### all967#### options.all968969Type: `boolean`\970Default: `false`971972Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the subprocess with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).972Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property. They contain the combined/[interleaved](#ensuring-all-output-is-interleaved) output of the subprocess' `stdout` and `stderr`.973974#### lines974#### options.lines975976Type: `boolean`\977Default: `false`978979Set [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) as arrays of strings, splitting the subprocess' output into lines.979Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.980981This cannot be used if the [`encoding` option](#encoding) is binary.981This cannot be used if the [`encoding`](#optionsencoding) option is binary.982983#### encoding983#### options.encoding984985Type: `string`\986Default: `'utf8'`987
2 unmodified lines
990If it outputs binary data instead, this should be either:991- `'buffer'`: returns the binary output as an `Uint8Array`.992- `'hex'`, `'base64'`, `'base64url'`, [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.993994The output is available with [`result.stdout`](#stdout), [`result.stderr`](#stderr) and [`result.stdio`](#stdio).994The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).995996#### stripFinalNewline996#### options.stripFinalNewline997998Type: `boolean`\999Default: `true`10001001Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10021003If the [`lines` option](#lines) is true, this applies to each output line instead.1003If the [`lines`](#optionslines) option is true, this applies to each output line instead.10041005#### maxBuffer1005#### options.maxBuffer10061007Type: `number`\1008Default: `100_000_000`10091010Largest amount of data allowed on [`stdout`](#stdout), [`stderr`](#stderr) and [`stdio`](#stdio).1010Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).10111012When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](#ismaxbuffer) becomes `true`.1012When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](#resultismaxbuffer) becomes `true`.10131014This is measured:1015- By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).1016- If the [`encoding` option](#encoding) is `'buffer'`: in bytes.1017- If the [`lines` option](#lines) is `true`: in lines.1016- If the [`encoding`](#optionsencoding) option is `'buffer'`: in bytes.1017- If the [`lines`](#optionslines) option is `true`: in lines.1018- If a [transform in object mode](docs/transform.md#object-mode) is used: in objects.10191020By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).10211022#### ipc1022#### options.ipc10231024Type: `boolean`\1025Default: `true` if the [`node`](#node) option is enabled, `false` otherwise1025Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise10261027Enables exchanging messages with the subprocess using [`subprocess.send(value)`](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [`subprocess.on('message', (value) => {})`](https://nodejs.org/api/child_process.html#event-message).10281029#### serialization1029#### options.serialization10301031Type: `string`\1032Default: `'advanced'`10331034Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#ipc) option:1034Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option:1035 - `json`: Uses `JSON.stringify()` and `JSON.parse()`.1036 - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)10371038[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)10391040#### detached1040#### options.detached10411042Type: `boolean`\1043Default: `false`10441045Prepare subprocess to run independently of the current process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).10461047#### cleanup1047#### options.cleanup10481049Type: `boolean`\1050Default: `true`10511052Kill the subprocess when the current process exits unless either:1053 - the subprocess is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)1054 - the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit10551056#### timeout1056#### options.timeout10571058Type: `number`\1059Default: `0`10601061If `timeout` is greater than `0`, the subprocess will be [terminated](#killsignal) if it runs for longer than that amount of milliseconds.1061If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.10621063#### cancelSignal1063#### options.cancelSignal10641065Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)10661067You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).10681069When `AbortController.abort()` is called, [`.isCanceled`](#iscanceled) becomes `true`.1069When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.10701071#### forceKillAfterDelay1071#### options.forceKillAfterDelay10721073Type: `number | false`\1074Default: `5000`1075
1 unmodified line
10771078The grace period is 5 seconds by default. This feature can be disabled with `false`.10791080This works when the subprocess is terminated by either:1081- the [`cancelSignal`](#cancelsignal), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option1081- the [`cancelSignal`](#optionscancelsignal), [`timeout`](#optionstimeout), [`maxBuffer`](#optionsmaxbuffer) or [`cleanup`](#optionscleanup) option1082- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments10831084This does not work when the subprocess is terminated by either:1085- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with an argument
1 unmodified line
1087- sending a termination signal from another process10881089Also, this does not work on Windows, because Windows [doesn't support signals](https://nodejs.org/api/process.html#process_signal_events): `SIGKILL` and `SIGTERM` both terminate the subprocess immediately. Other packages (such as [`taskkill`](https://github.com/sindresorhus/taskkill)) can be used to achieve fail-safe termination on Windows.10901091#### killSignal1091#### options.killSignal10921093Type: `string | number`\1094Default: `SIGTERM`10951096Signal used to terminate the subprocess when:1097- using the [`cancelSignal`](#cancelsignal), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option1097- using the [`cancelSignal`](#optionscancelsignal), [`timeout`](#optionstimeout), [`maxBuffer`](#optionsmaxbuffer) or [`cleanup`](#optionscleanup) option1098- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments10991100This can be either a name (like `"SIGTERM"`) or a number (like `9`).11011102#### argv01102#### options.argv011031104Type: `string`11051106Explicitly set the value of `argv[0]` sent to the subprocess. This will be set to `file` if not specified.11071108#### uid1108#### options.uid11091110Type: `number`11111112Sets the user identity of the subprocess.11131114#### gid1114#### options.gid11151116Type: `number`11171118Sets the group identity of the subprocess.11191120#### windowsVerbatimArguments1120#### options.windowsVerbatimArguments11211122Type: `boolean`\1123Default: `false`11241125If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`.11261127#### windowsHide1127#### options.windowsHide11281129Type: `boolean`\1130Default: `true`1131
2 unmodified lines
1134## Tips11351136### Redirect stdin/stdout/stderr to multiple destinations11371138The [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options can be an array of values.1138The [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options can be an array of values.1139The following example redirects `stdout` to both the terminal and an `output.txt` file, while also retrieving its value programmatically.11401141```js1142const {stdout} = await execa('npm', ['install'], {stdout: ['inherit', './output.txt', 'pipe']});
3 unmodified lines
1146When combining `inherit` with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.11471148### Redirect a Node.js stream from/to stdin/stdout/stderr11491150When passing a Node.js stream to the [`stdin`](#stdin), [`stdout`](#stdout-1) or [`stderr`](#stderr-1) option, Node.js requires that stream to have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules. Otherwise the following error is thrown.1150When passing a Node.js stream to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) or [`stderr`](#optionsstderr) option, Node.js requires that stream to have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules. Otherwise the following error is thrown.11511152```1153TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.1154```
54 unmodified lines
1209```12101211### Ensuring `all` output is interleaved12121213The `all` [stream](#all) and [string/`Uint8Array`](#all-1) properties are guaranteed to interleave [`stdout`](#stdout) and [`stderr`](#stderr).1213The `subprocess.all` [stream](#subprocessall) and `result.all` [string/`Uint8Array`](#resultall) property are guaranteed to interleave [`stdout`](#resultstdout) and [`stderr`](#resultstderr).12141215However, for performance reasons, the subprocess might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This prevents proper interleaving.12161217For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.
35 unmodified lines