Skip to content
Myr

readme.md

This file

Path

readme.md

1,225 lines · 48.7 KiB · Markdown

Last changed by

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

History of this file

Take it

The walk stopped after 200 commits: lines older than 4fb84f0 point at it.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1–33why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="media/logo_dark.svg">3 <img alt="execa logo" src="media/logo.svg" width="400">4</picture>5<br>67[![Coverage Status](https://codecov.io/gh/sindresorhus/execa/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/execa)89> Process execution for humans1011<br>1213---1415<div align="center">16 <p>17 <p>18 <sup>19 <a href="https://github.com/sponsors/sindresorhus">Sindre's open source work is supported by the community</a>20 </sup>21 </p>22 <sup>Special thanks to:</sup>23 <br>24 <br>25 <a href="https://transloadit.com?utm_source=sindresorhus&utm_medium=referral&utm_campaign=sponsorship&utm_content=execa">26 <picture>27 <source width="360" media="(prefers-color-scheme: dark)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo-dark.svg">28 <source width="360" media="(prefers-color-scheme: light)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo.svg">29 <img width="360" src="https://sindresorhus.com/assets/thanks/transloadit-logo.svg" alt="Transloadit logo">30 </picture>31 </a>32 <br>33 <br>

Meta tweaksSindre Sorhusbefore adoption1915060

lines 34–38why, one step back
34 <a href="https://coderabbit.ai?utm_source=sindre&utm_medium=execa">
35 <img width="300" src="https://sindresorhus.com/assets/thanks/coderabbit-logo.png" alt="CodeRabbit logo">36 </a>37 <br>38 <br>

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 39–49why, one step back
39 </p>
40</div>4142---4344<br>4546## Why4748This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with:49

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 50–51why, one step back
50- [Promise interface](#execafile-arguments-options).
51- [Script interface](docs/scripts.md) and [template strings](#template-string-syntax), like `zx`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 52–53why, one step back
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`.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 54why, one step back
54- [Cleans up](#cleanup) subprocesses when the current process ends.

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

line 55why, one step back
55- Redirect [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1) from/to files, streams, iterables, strings, `Uint8Array` or [objects](docs/transform.md#object-mode).

Line-wise transforms (#699)ehmickybefore adoption6dd804f

line 56why, one step back
56- [Transform](docs/transform.md) `stdin`/`stdout`/`stderr` with simple functions.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 57–58why, one step back
57- Iterate over [each text line](docs/transform.md#binary-data) output by the subprocess.
58- [Fail-safe subprocess termination](#forcekillafterdelay).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 59–60why, one step back
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()`.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 61why, one step back
61- Convenience methods to pipe subprocesses' [input](#input) and [output](#redirect-output-to-a-file).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 62–83why, one step back
62- [Verbose mode](#verbose-mode) for debugging.
63- More descriptive errors.64- Higher max buffer: 100 MB instead of 1 MB.6566## Install6768```sh69npm install execa70```7172## Usage7374### Promise interface7576```js77import {execa} from 'execa';7879const {stdout} = await execa('echo', ['unicorns']);80console.log(stdout);81//=> 'unicorns'82```83

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 84why, one step back
84#### Global/shared options

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 85why, one step back
85

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 86–87why, one step back
86```js
87import {execa as execa_} from 'execa';

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 88why, one step back
88

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 89–96why, one step back
89const execa = execa_({verbose: 'full'});
9091await execa('echo', ['unicorns']);92//=> 'unicorns'93```9495### Template string syntax96

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 97–99why, one step back
97#### Basic
9899```js

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 100why, one step back
100import {execa} from 'execa';

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 101why, one step back
101

Refactor tests (#934)ehmickybefore adoption52c4bde

line 102why, one step back
102const arg = 'unicorns';

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 103–105why, one step back
103const {stdout} = await execa`echo ${arg} & rainbows!`;
104console.log(stdout);105//=> 'unicorns & rainbows!'

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 106–110why, one step back
106```
107108#### Multiple arguments109110```js

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 111why, one step back
111import {execa} from 'execa';

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 112–113why, one step back
112
113const args = ['unicorns', '&', 'rainbows!'];

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 114why, one step back
114const {stdout} = await execa`echo ${args}`;

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 115–121why, one step back
115console.log(stdout);
116//=> 'unicorns & rainbows!'117```118119#### With options120121```js

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 122why, one step back
122import {execa} from 'execa';

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 123why, one step back
123

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 124why, one step back
124await execa({verbose: 'full'})`echo unicorns`;

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 125–127why, one step back
125//=> 'unicorns'
126```127

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 128why, one step back
128### Scripts

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 129why, one step back
129

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 130why, one step back
130For more information about Execa scripts, please see [this page](docs/scripts.md).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 131why, one step back
131

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 132why, one step back
132#### Basic

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 133why, one step back
133

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

lines 134–136why, one step back
134```js
135import {$} from 'execa';136

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 137–138why, one step back
137const branch = await $`git branch --show-current`;
138await $`dep deploy --branch=${branch}`;

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

lines 139–140why, one step back
139```
140

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 141–148why, one step back
141#### Verbose mode
142143```sh144> node file.js145unicorns146rainbows147148> NODE_DEBUG=execa node file.js

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

line 149why, one step back
149[19:49:00.360] [0] $ echo unicorns

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 150why, one step back
150unicorns

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

line 151why, one step back
151[19:49:00.383] [0] √ (done in 23ms)

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

line 152why, one step back
152[19:49:00.383] [1] $ echo rainbows

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 153why, one step back
153rainbows

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

line 154why, one step back
154[19:49:00.404] [1] √ (done in 21ms)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 155–164why, one step back
155```
156157### Input/output158159#### Redirect output to a file160161```js162import {execa} from 'execa';163164// Similar to `echo unicorns > stdout.txt` in Bash

Only allow child processes as argument to `.pipeStdout()` (#752)ehmickybefore adoptiond16c305

line 165why, one step back
165await execa('echo', ['unicorns'], {stdout: {file: 'stdout.txt'}});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 166–167why, one step back
166
167// Similar to `echo unicorns 2> stdout.txt` in Bash

Only allow child processes as argument to `.pipeStdout()` (#752)ehmickybefore adoptiond16c305

line 168why, one step back
168await execa('echo', ['unicorns'], {stderr: {file: 'stderr.txt'}});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 169–170why, one step back
169
170// Similar to `echo unicorns &> stdout.txt` in Bash

Only allow child processes as argument to `.pipeStdout()` (#752)ehmickybefore adoptiond16c305

line 171why, one step back
171await execa('echo', ['unicorns'], {stdout: {file: 'all.txt'}, stderr: {file: 'all.txt'}});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 172–184why, one step back
172```
173174#### Redirect input from a file175176```js177import {execa} from 'execa';178179// Similar to `cat < stdin.txt` in Bash180const {stdout} = await execa('cat', {inputFile: 'stdin.txt'});181console.log(stdout);182//=> 'unicorns'183```184

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 185why, one step back
185#### Save and pipe output from a subprocess

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 186–189why, one step back
186
187```js188import {execa} from 'execa';189

Only allow child processes as argument to `.pipeStdout()` (#752)ehmickybefore adoptiond16c305

line 190why, one step back
190const {stdout} = await execa('echo', ['unicorns'], {stdout: ['pipe', 'inherit']});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 191–195why, one step back
191// Prints `unicorns`
192console.log(stdout);193// Also returns 'unicorns'194```195

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 196why, one step back
196#### Pipe multiple subprocesses

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 197–200why, one step back
197
198```js199import {execa} from 'execa';200

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 201–202why, one step back
201// Similar to `npm run build | sort | head -n2` in Bash
202const {stdout, pipedFrom} = await execa('npm', ['run', 'build'])

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 203–204why, one step back
203 .pipe('sort')
204 .pipe('head', ['-n2']);

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 205–207why, one step back
205console.log(stdout); // Result of `head -n2`
206console.log(pipedFrom[0]); // Result of `sort`207console.log(pipedFrom[0].pipedFrom[0]); // Result of `npm run build`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 208–209why, one step back
208```
209

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 210–219why, one step back
210#### Pipe with template strings
211212```js213import {execa} from 'execa';214215await execa`npm run build`216 .pipe`sort`217 .pipe`head -n2`;218```219

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 220–224why, one step back
220#### Iterate over output lines
221222```js223import {execa} from 'execa';224

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 225why, one step back
225for await (const line of execa`npm run build`)) {

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 226–231why, one step back
226 if (line.includes('ERROR')) {
227 console.log(line);228 }229}230```231

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 232–242why, one step back
232### Handling Errors
233234```js235import {execa} from 'execa';236237// Catching an error238try {239 await execa('unknown', ['command']);240} catch (error) {241 console.log(error);242 /*

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 243–246why, one step back
243 ExecaError: Command failed with ENOENT: unknown command
244 spawn unknown ENOENT245 at ...246 at ... {

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 247why, one step back
247 shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 248–250why, one step back
248 originalMessage: 'spawn unknown ENOENT',
249 command: 'unknown command',250 escapedCommand: 'unknown command',

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 251–252why, one step back
251 cwd: '/path/to/cwd',
252 durationMs: 28.217566,

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 253–255why, one step back
253 failed: true,
254 timedOut: false,255 isCanceled: false,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 256why, one step back
256 isTerminated: false,

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 257why, one step back
257 code: 'ENOENT',

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 258–261why, one step back
258 stdout: '',
259 stderr: '',260 stdio: [undefined, '', ''],261 pipedFrom: []

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 262–270why, one step back
262 [cause]: Error: spawn unknown ENOENT
263 at ...264 at ... {265 errno: -2,266 code: 'ENOENT',267 syscall: 'spawn unknown',268 path: 'unknown',269 spawnargs: [ 'command' ]270 }

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 271–281why, one step back
271 }
272 */273}274```275276## API277278### Methods279280#### execa(file, arguments?, options?)281

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

lines 282–283why, one step back
282`file`: `string | URL`\
283`arguments`: `string[]`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 284why, one step back
284`options`: [`Options`](#options)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 285why, one step back
285_Returns_: [`Subprocess`](#subprocess)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 286why, one step back
286

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

lines 287–288why, one step back
287Executes a command using `file ...arguments`.
288

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 289why, one step back
289Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces, tabs and newlines.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 290why, one step back
290

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 291–292why, one step back
291#### execa\`command\`
292#### execa(options)\`command\`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 293why, one step back
293

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 294why, one step back
294`command`: `string`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 295why, one step back
295`options`: [`Options`](#options)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 296why, one step back
296_Returns_: [`Subprocess`](#subprocess)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 297why, one step back
297

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 298why, one step back
298Executes a command. `command` is a [template string](#template-string-syntax) and includes both the `file` and its `arguments`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 299why, one step back
299

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 300why, one step back
300The `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.

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 301why, one step back
301

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 302why, one step back
302Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces, tabs and newlines must use `${}` like `` execa`echo ${'has space'}` ``.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 303why, one step back
303

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 304why, one step back
304The `command` template string can use [multiple lines and indentation](docs/scripts.md#multiline-commands).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 305why, one step back
305

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 306why, one step back
306#### execa(options)

Allow newlines in `$` (#843)ehmickybefore adoption1315486

line 307why, one step back
307

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 308–309why, one step back
308`options`: [`Options`](#options)\
309_Returns_: [`execa`](#execafile-arguments-options)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 310why, one step back
310

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 311why, one step back
311Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 312why, one step back
312

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 313why, one step back
313This allows setting global options or [sharing options](#globalshared-options) between multiple commands.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 314why, one step back
314

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 315–316why, one step back
315#### execaSync(file, arguments?, options?)
316#### execaSync\`command\`

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 317why, one step back
317

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 318why, one step back
318Same as [`execa()`](#execafile-arguments-options) but synchronous.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 319why, one step back
319

Improve documentation of `execaSync()` (#935)ehmickybefore adoption1c12be9

line 320why, one step back
320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 321why, one step back
321

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

line 322why, one step back
322Cannot use the following options: [`cleanup`](#cleanup), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). [`result.all`](#all-1) is not interleaved. Also, 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), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 323–328why, one step back
323
324#### $(file, arguments?, options?)325326`file`: `string | URL`\327`arguments`: `string[]`\328`options`: [`Options`](#options)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 329why, one step back
329_Returns_: [`Subprocess`](#subprocess)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 330why, one step back
330

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 331why, one step back
331Same as [`execa()`](#execafile-arguments-options) but using the [`stdin: 'inherit'`](#stdin) and [`preferLocal: true`](#preferlocal) options.

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 332why, one step back
332

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 333why, one step back
333Just 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()`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 334why, one step back
334

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 335why, one step back
335This is the preferred method when executing multiple commands in a script file. For more information, please see [this page](docs/scripts.md).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 336why, one step back
336

Add `node` option (#804)ehmickybefore adoption663136b

lines 337–338why, one step back
337#### execaNode(scriptPath, arguments?, options?)
338

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 339why, one step back
339`scriptPath`: `string | URL`\

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 340why, one step back
340`arguments`: `string[]`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 341why, one step back
341`options`: [`Options`](#options)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 342why, one step back
342_Returns_: [`Subprocess`](#subprocess)

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 343why, one step back
343

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 344why, one step back
344Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#node) option.

Add `node` option (#804)ehmickybefore adoption663136b

lines 345–346why, one step back
345Executes a Node.js file using `node scriptPath ...arguments`.
346

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 347–348why, one step back
347Just like `execa()`, this can use the [template string syntax](#execacommand) or [bind options](#execaoptions).
348

Improve documentation of main methods (#860)ehmickybefore adoption3bb0d61

line 349why, one step back
349This is the preferred method when executing Node.js files.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 350why, one step back
350

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 351why, one step back
351#### execaCommand(command, options?)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 352why, one step back
352

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 353–355why, one step back
353`command`: `string`\
354`options`: [`Options`](#options)\355_Returns_: [`Subprocess`](#subprocess)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 356why, one step back
356

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 357why, one step back
357[`execa`](#execafile-arguments-options) with the [template string syntax](#execacommand) allows the `file` or the `arguments` to be user-defined (by injecting them with `${}`). However, if _both_ the `file` and the `arguments` are user-defined, _and_ those are supplied as a single string, then `execaCommand(command)` must be used instead.

Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd

line 358why, one step back
358

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 359why, one step back
359This is only intended for very specific cases, such as a REPL. This should be avoided otherwise.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 360why, one step back
360

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 361–364why, one step back
361Just like `execa()`, this can [bind options](#execaoptions). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.
362363Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.364

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 365–368why, one step back
365### Shell syntax
366367For 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.368

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 369why, one step back
369### subprocess

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 370–371why, one step back
370
371The return value of all [asynchronous methods](#methods) is both:

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 372why, one step back
372- a `Promise` resolving or rejecting with a [`subprocessResult`](#subprocessResult).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 373–382why, one step back
373- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties.
374375#### all376377Type: `ReadableStream | undefined`378379Stream [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).380381This is `undefined` if either:382- the [`all` option](#all-2) is `false` (the default value)

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 383why, one step back
383- 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)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 384why, one step back
384

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 385why, one step back
385#### pipe(file, arguments?, options?)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 386why, one step back
386

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 387–388why, one step back
387`file`: `string | URL`\
388`arguments`: `string[]`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 389why, one step back
389`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 390why, one step back
390_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 391why, one step back
391

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 392why, one step back
392[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.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 393why, one step back
393

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 394why, one step back
394This 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.

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 395why, one step back
395

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 396why, one step back
396This can be called multiple times to chain a series of subprocesses.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 397why, one step back
397

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 398why, one step back
398Multiple subprocesses can be piped to the same subprocess. Conversely, the same subprocess can be piped to multiple other subprocesses.

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 399why, one step back
399

Fix Markdown typo (#869)ehmickybefore adoptionc8ba426

lines 400–401why, one step back
400#### pipe\`command\`
401#### pipe(options)\`command\`

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 402why, one step back
402

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 403why, one step back
403`command`: `string`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 404why, one step back
404`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 405why, one step back
405_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 406why, one step back
406

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 407why, one step back
407Like [`.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).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 408why, one step back
408

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 409why, one step back
409#### pipe(secondSubprocess, pipeOptions?)

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 410why, one step back
410

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 411why, one step back
411`secondSubprocess`: [`execa()` return value](#subprocess)\

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 412why, one step back
412`pipeOptions`: [`PipeOptions`](#pipeoptions)\

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 413why, one step back
413_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 414why, one step back
414

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 415why, one step back
415Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using the [return value](#subprocess) of another `execa()` call instead.

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 416why, one step back
416

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 417why, one step back
417This is the most advanced method to pipe subprocesses. It is useful in specific cases, such as piping multiple subprocesses to the same subprocess.

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 418why, one step back
418

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 419why, one step back
419##### pipeOptions

Only allow child processes as argument to `.pipeStdout()` (#752)ehmickybefore adoptiond16c305

line 420why, one step back
420

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 421–424why, one step back
421Type: `object`
422423##### pipeOptions.from424

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 425why, one step back
425Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 426–427why, one step back
426Default: `"stdout"`
427

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 428why, one step back
428Which stream to pipe from the source subprocess. A file descriptor like `"fd3"` can also be passed.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 429–430why, one step back
429
430`"all"` pipes both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

lines 431–433why, one step back
431
432##### pipeOptions.to433

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 434why, one step back
434Type: `"stdin" | "fd3" | "fd4" | ...`\

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

lines 435–436why, one step back
435Default: `"stdin"`
436

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 437why, one step back
437Which stream to pipe to the destination subprocess. A file descriptor like `"fd3"` can also be passed.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 438why, one step back
438

Rename `signal` option to `unpipeSignal` (#852)ehmickybefore adoption9dc1141

line 439why, one step back
439##### pipeOptions.unpipeSignal

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 440–442why, one step back
440
441Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)442

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 443why, one step back
443Unpipe the subprocess when the signal aborts.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 444why, one step back
444

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 445why, one step back
445The [`.pipe()`](#pipefile-arguments-options) method will be rejected with a cancellation error.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 446why, one step back
446

Add `.kill(signal, error)` (#836)ehmickybefore adoption30a662d

lines 447–448why, one step back
447#### kill(signal, error?)
448#### kill(error?)

Add `.kill(error)` (#811)ehmickybefore adoption9cbb817

line 449why, one step back
449

Add `.kill(signal, error)` (#836)ehmickybefore adoption30a662d

lines 450–451why, one step back
450`signal`: `string | number`\
451`error`: `Error`\

Add `.kill(error)` (#811)ehmickybefore adoption9cbb817

lines 452–453why, one step back
452_Returns_: `boolean`
453

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 454why, one step back
454Sends 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.

Add `.kill(error)` (#811)ehmickybefore adoption9cbb817

line 455why, one step back
455

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 456why, one step back
456This returns `false` when the signal could not be sent, for example when the subprocess has already exited.

Add `.kill(error)` (#811)ehmickybefore adoption9cbb817

line 457why, one step back
457

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 458why, one step back
458When 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).

Add `.kill(error)` (#811)ehmickybefore adoption9cbb817

lines 459–461why, one step back
459
460[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)461

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 462–476why, one step back
462#### [Symbol.asyncIterator]()
463464_Returns_: `AsyncIterable`465466Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.467468The 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).469470#### iterable(readableOptions?)471472`readableOptions`: [`ReadableOptions`](#readableoptions)\473_Returns_: `AsyncIterable`474475Same as [`subprocess[Symbol.asyncIterator]`](#symbolasynciterator) except [options](#readableoptions) can be provided.476

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 477why, one step back
477#### readable(readableOptions?)

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 478why, one step back
478

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 479why, one step back
479`readableOptions`: [`ReadableOptions`](#readableoptions)\

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 480–485why, one step back
480_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream
481482Converts the subprocess to a readable stream.483484Unlike [`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.485

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 486why, one step back
486Before 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).

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 487why, one step back
487

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 488why, one step back
488#### writable(writableOptions?)

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 489why, one step back
489

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 490why, one step back
490`writableOptions`: [`WritableOptions`](#writableoptions)\

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 491–496why, one step back
491_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream
492493Converts the subprocess to a writable stream.494495Unlike [`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.496

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 497why, one step back
497Before 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).

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 498why, one step back
498

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 499why, one step back
499#### duplex(duplexOptions?)

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 500why, one step back
500

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 501why, one step back
501`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 502–507why, one step back
502_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream
503504Converts the subprocess to a duplex stream.505506The 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.507

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 508why, one step back
508Before 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).

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 509why, one step back
509

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 510why, one step back
510##### readableOptions

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 511–513why, one step back
511
512Type: `object`513

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 514why, one step back
514##### readableOptions.from

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 515why, one step back
515

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 516why, one step back
516Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 517–518why, one step back
517Default: `"stdout"`
518

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 519why, one step back
519Which stream to read from the subprocess. A file descriptor like `"fd3"` can also be passed.

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 520–522why, one step back
520
521`"all"` reads both `stdout` and `stderr`. This requires the [`all` option](#all-2) to be `true`.522

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 523why, one step back
523##### readableOptions.binary

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 524why, one step back
524

Prevent handling binary data like text data (#924)ehmickybefore adoptionaf3aefd

lines 525–526why, one step back
525Type: `boolean`\
526Default: `false` with [`.iterable()`](#iterablereadableoptions), `true` with [`.readable()`](#readablereadableoptions)/[`.duplex()`](#duplexduplexoptions)

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 527why, one step back
527

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

lines 528–529why, one step back
528If `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).
529

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 530why, one step back
530If `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).

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 531why, one step back
531

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 532why, one step back
532This is always `true` when the [`encoding` option](#encoding) is binary.

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 533why, one step back
533

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

lines 534–536why, one step back
534##### readableOptions.preserveNewlines
535536Type: `boolean`\

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 537why, one step back
537Default: `false` with [`.iterable()`](#iterablereadableoptions), `true` with [`.readable()`](#readablereadableoptions)/[`.duplex()`](#duplexduplexoptions)

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

lines 538–546why, one step back
538
539If both this option and the [`binary` option](#readableoptionsbinary) is `false`, newlines are stripped from each line.540541##### writableOptions542543Type: `object`544545##### writableOptions.to546

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 547why, one step back
547Type: `"stdin" | "fd3" | "fd4" | ...`\

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 548–549why, one step back
548Default: `"stdin"`
549

Rename `from|to: 3` to `from|to: 'fd3'` (#920)ehmickybefore adoption8dfdd91

line 550why, one step back
550Which stream to write to the subprocess. A file descriptor like `"fd3"` can also be passed.

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 551why, one step back
551

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 552why, one step back
552### SubprocessResult

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 553–555why, one step back
553
554Type: `object`555

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 556why, one step back
556Result of a subprocess execution.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 557why, one step back
557

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 558why, one step back
558When the subprocess [fails](#failed), it is rejected with an [`ExecaError`](#execaerror) instead.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 559–565why, one step back
559
560#### command561562Type: `string`563564The file and arguments that were run, for logging purposes.565

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 566why, one step back
566This is not escaped and should not be executed directly as a subprocess, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 567–571why, one step back
567
568#### escapedCommand569570Type: `string`571

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 572why, one step back
572Same as [`command`](#command) but escaped.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 573why, one step back
573

Better escaping of `result.escapedCommand` (#875)ehmickybefore adoption7b044bb

lines 574–576why, one step back
574Unlike `command`, control characters are escaped, which makes it safe to print in a terminal.
575576This can also be copied and pasted into a shell, for debugging purposes.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 577why, one step back
577Since the escaping is fairly basic, this should not be executed directly as a subprocess, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 578why, one step back
578

Re-order return value properties (#801)ehmickybefore adoption72836f3

line 579why, one step back
579#### cwd

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 580why, one step back
580

Re-order return value properties (#801)ehmickybefore adoption72836f3

line 581why, one step back
581Type: `string`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 582why, one step back
582

Improve `cwd` option (#803)ehmickybefore adoption2fd9351

line 583why, one step back
583The [current directory](#cwd-1) in which the command was run.

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 584–588why, one step back
584
585#### durationMs586587Type: `number`588

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 589why, one step back
589Duration of the subprocess, in milliseconds.

Document and type `exitCode` being `undefined` (#680)ehmickybefore adoption95e5754

line 590why, one step back
590

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 591–592why, one step back
591#### stdout
592

Line-wise standard streams (#741)ehmickybefore adoption479d12e

line 593why, one step back
593Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 594why, one step back
594

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 595why, one step back
595The output of the subprocess on `stdout`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 596why, one step back
596

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 597why, one step back
597This 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).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 598–600why, one step back
598
599#### stderr600

Line-wise standard streams (#741)ehmickybefore adoption479d12e

line 601why, one step back
601Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 602why, one step back
602

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 603why, one step back
603The output of the subprocess on `stderr`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 604why, one step back
604

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 605why, one step back
605This 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).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 606–608why, one step back
606
607#### all608

Line-wise standard streams (#741)ehmickybefore adoption479d12e

line 609why, one step back
609Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 610why, one step back
610

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 611why, one step back
611The output of the subprocess with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 612–614why, one step back
612
613This is `undefined` if either:614- the [`all` option](#all-2) is `false` (the default value)

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 615why, one step back
615- 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)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 616why, one step back
616

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 617why, one step back
617This 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).

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

line 618why, one step back
618

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 619–620why, one step back
619#### stdio
620

Line-wise standard streams (#741)ehmickybefore adoption479d12e

line 621why, one step back
621Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 622why, one step back
622

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 623why, one step back
623The output of the subprocess on [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [other file descriptors](#stdio-1).

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 624why, one step back
624

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 625why, one step back
625Items 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).

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 626why, one step back
626

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 627–630why, one step back
627#### failed
628629Type: `boolean`630

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 631why, one step back
631Whether the subprocess failed to run.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 632–636why, one step back
632
633#### timedOut634635Type: `boolean`636

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 637why, one step back
637Whether the subprocess timed out.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 638–642why, one step back
638
639#### isCanceled640641Type: `boolean`642

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 643why, one step back
643Whether the subprocess was canceled using the [`cancelSignal`](#cancelsignal) option.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 644–648why, one step back
644
645#### isTerminated646647Type: `boolean`648

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 649why, one step back
649Whether the subprocess was terminated by a signal (like `SIGTERM`) sent by either:

Improve process termination (#724)ehmickybefore adoption1c48d37

lines 650–651why, one step back
650- The current process.
651- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 652why, one step back
652

Re-order return value properties (#801)ehmickybefore adoption72836f3

lines 653–656why, one step back
653#### exitCode
654655Type: `number | undefined`656

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 657why, one step back
657The numeric exit code of the subprocess that was run.

Re-order return value properties (#801)ehmickybefore adoption72836f3

line 658why, one step back
658

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 659why, one step back
659This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#signal).

Re-order return value properties (#801)ehmickybefore adoption72836f3

line 660why, one step back
660

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 661–664why, one step back
661#### signal
662663Type: `string | undefined`664

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 665why, one step back
665The name of the signal (like `SIGTERM`) that terminated the subprocess, sent by either:

Improve process termination (#724)ehmickybefore adoption1c48d37

lines 666–667why, one step back
666- The current process.
667- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 668why, one step back
668

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 669why, one step back
669If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 670–674why, one step back
670
671#### signalDescription672673Type: `string | undefined`674

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 675why, one step back
675A human-friendly description of the signal that was used to terminate the subprocess. For example, `Floating point arithmetic error`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 676why, one step back
676

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 677why, one step back
677If 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.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 678–680why, one step back
678
679#### pipedFrom680

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 681why, one step back
681Type: [`Array<SubprocessResult | ExecaError>`](#subprocessresult)

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 682why, one step back
682

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 683why, one step back
683Results 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.

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 684why, one step back
684

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 685why, one step back
685This array is initially empty and is populated each time the [`.pipe()`](#pipefile-arguments-options) method resolves.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 686why, one step back
686

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 687–736why, one step back
687### ExecaError
688### ExecaSyncError689690Type: `Error`691692Exception thrown when the subprocess [fails](#failed), either:693- its [exit code](#exitcode) is not `0`694- it was [terminated](#isterminated) with a [signal](#signal), including [`.kill()`](#killerror)695- [timing out](#timedout)696- [being canceled](#iscanceled)697- there's not enough memory or there are already too many subprocesses698699This has the same shape as [successful results](#subprocessresult), with the following additional properties.700701#### message702703Type: `string`704705Error 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.706707The subprocess [`stderr`](#stderr), [`stdout`](#stdout) and other [file descriptors' output](#stdio) are appended to the end, separated with newlines and not interleaved.708709#### shortMessage710711Type: `string`712713This is the same as the [`message` property](#message) except it does not include the subprocess [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio).714715#### originalMessage716717Type: `string | undefined`718719Original 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.720721This exists only if the subprocess exited due to an `error` event or a timeout.722723#### cause724725Type: `unknown | undefined`726727Underlying error, if there is one. For example, this is set by [`.kill(error)`](#killerror).728729This is usually an `Error` instance.730731#### code732733Type: `string | undefined`734735Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.736

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 737–740why, one step back
737### options
738739Type: `object`740

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 741why, one step back
741This lists all Execa options, including some options which are the same as for [`child_process#spawn()`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)/[`child_process#exec()`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 742why, one step back
742

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 743–744why, one step back
743#### reject
744

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 745–747why, one step back
745Type: `boolean`\
746Default: `true`747

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 748why, one step back
748Setting this to `false` resolves the promise with the [error](#execaerror) instead of rejecting it.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 749why, one step back
749

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 750–766why, one step back
750#### shell
751752Type: `boolean | string | URL`\753Default: `false`754755If `true`, runs `file` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.756757We recommend against using this option since it is:758- not cross-platform, encouraging shell-specific syntax.759- slower, because of the additional shell interpretation.760- unsafe, potentially allowing command injection.761762#### cwd763764Type: `string | URL`\765Default: `process.cwd()`766

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 767why, one step back
767Current working directory of the subprocess.

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 768why, one step back
768

Merge `execPath` and `nodePath` options (#812)ehmickybefore adoptionfa04e3c

line 769why, one step back
769This is also used to resolve the [`nodePath`](#nodepath) option when it is a relative path.

Improve `cwd` option (#803)ehmickybefore adoption2fd9351

line 770why, one step back
770

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 771–777why, one step back
771#### env
772773Type: `object`\774Default: `process.env`775776Environment key-value pairs.777

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 778why, one step back
778Unless the [`extendEnv` option](#extendenv) is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 779–784why, one step back
779
780#### extendEnv781782Type: `boolean`\783Default: `true`784

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 785why, one step back
785If `true`, the subprocess uses both the [`env` option](#env) and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 786–787why, one step back
786If `false`, only the `env` option is used, not `process.env`.
787

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 788–790why, one step back
788#### preferLocal
789790Type: `boolean`\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 791why, one step back
791Default: `true` with [`$`](#file-arguments-options), `false` otherwise

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 792–802why, one step back
792
793Prefer locally installed binaries when looking for a binary to execute.\794If you `$ npm install foo`, you can then `execa('foo')`.795796#### localDir797798Type: `string | URL`\799Default: `process.cwd()`800801Preferred path to find locally installed binaries in (use with `preferLocal`).802

Add `node` option (#804)ehmickybefore adoption663136b

line 803why, one step back
803#### node

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 804why, one step back
804

Add `node` option (#804)ehmickybefore adoption663136b

lines 805–806why, one step back
805Type: `boolean`\
806Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 807why, one step back
807

Add `node` option (#804)ehmickybefore adoption663136b

line 808why, one step back
808If `true`, runs with Node.js. The first argument must be a Node.js file.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 809why, one step back
809

Add `node` option (#804)ehmickybefore adoption663136b

line 810why, one step back
810#### nodeOptions

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 811why, one step back
811

Add `node` option (#804)ehmickybefore adoption663136b

lines 812–813why, one step back
812Type: `string[]`\
813Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 814why, one step back
814

Add `node` option (#804)ehmickybefore adoption663136b

line 815why, one step back
815List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#nodepath).

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 816why, one step back
816

Add `node` option (#804)ehmickybefore adoption663136b

lines 817–820why, one step back
817Requires the [`node`](#node) option to be `true`.
818819#### nodePath820

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 821why, one step back
821Type: `string | URL`\

Add `node` option (#804)ehmickybefore adoption663136b

line 822why, one step back
822Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 823why, one step back
823

Merge `execPath` and `nodePath` options (#812)ehmickybefore adoptionfa04e3c

line 824why, one step back
824Path to the Node.js executable.

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 825why, one step back
825

Merge `execPath` and `nodePath` options (#812)ehmickybefore adoptionfa04e3c

line 826why, one step back
826For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version.

Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682

lines 827–828why, one step back
827
828Requires the [`node`](#node) option to be `true`.

Add `node` option (#804)ehmickybefore adoption663136b

line 829why, one step back
829

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 830–831why, one step back
830#### verbose
831

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

lines 832–833why, one step back
832Type: `'none' | 'short' | 'full'`\
833Default: `'none'`

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 834why, one step back
834

Print errors with verbose option (#890)ehmickybefore adoption209f78f

line 835why, one step back
835If `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.

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 836why, one step back
836

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

lines 837–838why, one step back
837If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:
838- the [`stdout`](#stdout-1)/[`stderr`](#stderr-1) option is `ignore` or `inherit`.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 839why, one step back
839- 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).

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 840why, one step back
840- the [`encoding` option](#encoding) is binary.

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

lines 841–842why, one step back
841
842This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 843why, one step back
843

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 844–848why, one step back
844#### buffer
845846Type: `boolean`\847Default: `true`848

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 849why, one step back
849Whether to return the subprocess' output using the [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) properties.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 850why, one step back
850

Improve `buffer: false` behavior (#747)ehmickybefore adoptiona510995

lines 851–852why, one step back
851On failure, the [`error.stdout`](#stdout), [`error.stderr`](#stderr), [`error.all`](#all-1) and [`error.stdio`](#stdio) properties are used instead.
852

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 853why, one step back
853When `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.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 854–858why, one step back
854
855#### input856857Type: `string | Uint8Array | stream.Readable`858

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 859why, one step back
859Write some input to the subprocess' `stdin`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 860–866why, one step back
860
861See also the [`inputFile`](#inputfile) and [`stdin`](#stdin) options.862863#### inputFile864865Type: `string | URL`866

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 867why, one step back
867Use a file as input to the subprocess' `stdin`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 868–872why, one step back
868
869See also the [`input`](#input) and [`stdin`](#stdin) options.870871#### stdin872

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 873why, one step back
873Type: `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)\

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 874why, one step back
874Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 875why, one step back
875

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 876–877why, one step back
876[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:
877- `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 878–882why, one step back
878- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.
879- `'ignore'`: Do not use `stdin`.880- `'inherit'`: Re-use the current process' `stdin`.881- an integer: Re-use a specific file descriptor from the current process.882- a [Node.js `Readable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 883why, one step back
883- `{ file: 'path' }` object.

Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd

lines 884–886why, one step back
884- a file URL.
885- a web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).886- an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) or an [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 887why, one step back
887- an `Uint8Array`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 888–890why, one step back
888
889This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.890

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 891why, one step back
891This 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)

Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd

line 892why, one step back
892

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 893–894why, one step back
893#### stdout
894

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 895why, one step back
895Type: `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)\

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 896–897why, one step back
896Default: `pipe`
897

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 898–899why, one step back
898[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:
899- `'pipe'`: Sets [`subprocessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 900–904why, one step back
900- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.
901- `'ignore'`: Do not use `stdout`.902- `'inherit'`: Re-use the current process' `stdout`.903- an integer: Re-use a specific file descriptor from the current process.904- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 905why, one step back
905- `{ file: 'path' }` object.

Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd

lines 906–907why, one step back
906- a file URL.
907- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 908–910why, one step back
908
909This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.910

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 911why, one step back
911This 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)

Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd

line 912why, one step back
912

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 913–914why, one step back
913#### stderr
914

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 915why, one step back
915Type: `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)\

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 916–917why, one step back
916Default: `pipe`
917

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 918–919why, one step back
918[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:
919- `'pipe'`: Sets [`subprocessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 920–924why, one step back
920- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.
921- `'ignore'`: Do not use `stderr`.922- `'inherit'`: Re-use the current process' `stderr`.923- an integer: Re-use a specific file descriptor from the current process.924- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 925why, one step back
925- `{ file: 'path' }` object.

Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd

lines 926–927why, one step back
926- a file URL.
927- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 928–930why, one step back
928
929This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.930

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 931why, one step back
931This 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)

Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd

line 932why, one step back
932

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 933–934why, one step back
933#### stdio
934

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 935why, one step back
935Type: `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)\

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 936–941why, one step back
936Default: `pipe`
937938Like 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'}`.939940A single string can be used as a shortcut. For example, `{stdio: 'pipe'}` is the same as `{stdin: 'pipe', stdout: 'pipe', stderr: 'pipe'}`.941

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 942why, one step back
942The 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.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 943–948why, one step back
943
944#### all945946Type: `boolean`\947Default: `false`948

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 949why, one step back
949Add 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).

Line-wise standard streams (#741)ehmickybefore adoption479d12e

lines 950–955why, one step back
950
951#### lines952953Type: `boolean`\954Default: `false`955

Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc

line 956why, one step back
956Set [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) as arrays of strings, splitting the subprocess' output into lines.

Prevent handling binary data like text data (#924)ehmickybefore adoptionaf3aefd

line 957why, one step back
957

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 958why, one step back
958This cannot be used if the [`encoding` option](#encoding) is binary.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 959why, one step back
959

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 960why, one step back
960#### encoding

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 961why, one step back
961

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 962why, one step back
962Type: `string`\

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 963why, one step back
963Default: `'utf8'`

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 964why, one step back
964

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

lines 965–971why, one step back
965If the subprocess outputs text, specifies its character encoding, either `'utf8'` or `'utf16le'`.
966967If it outputs binary data instead, this should be either:968- `'buffer'`: returns the binary output as an `Uint8Array`.969- `'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.970971The output is available with [`result.stdout`](#stdout), [`result.stderr`](#stderr) and [`result.stdio`](#stdio).

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 972why, one step back
972

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 973–979why, one step back
973#### stripFinalNewline
974975Type: `boolean`\976Default: `true`977978Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.979

Strip newlines in transforms (#919)ehmickybefore adoption26e9150

lines 980–981why, one step back
980If the [`lines` option](#lines) is true, this applies to each output line instead.
981

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 982why, one step back
982#### maxBuffer

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 983why, one step back
983

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 984why, one step back
984Type: `number`\

Improve documentation of `maxBuffer` (#921)ehmickybefore adoptionbedb729

line 985why, one step back
985Default: `100_000_000`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 986why, one step back
986

Improve documentation of `maxBuffer` (#921)ehmickybefore adoptionbedb729

lines 987–993why, one step back
987Largest amount of data allowed on [`stdout`](#stdout), [`stderr`](#stderr) and [`stdio`](#stdio).
988989This is measured:990- By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).991- If the [`encoding` option](#encoding) is `'buffer'`: in bytes.992- If the [`lines` option](#lines) is `true`: in lines.993- If a [transform in object mode](docs/transform.md#object-mode) is used: in objects.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 994why, one step back
994

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 995why, one step back
995#### ipc

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 996why, one step back
996

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 997why, one step back
997Type: `boolean`\

Add `node` option (#804)ehmickybefore adoption663136b

line 998why, one step back
998Default: `true` if the [`node`](#node) option is enabled, `false` otherwise

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 999why, one step back
999

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1000why, one step back
1000Enables 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).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1001–1004why, one step back
1001
1002#### serialization10031004Type: `string`\

Change default value of `serialization` option to `advanced` (#905)ehmickybefore adoption4577582

line 1005why, one step back
1005Default: `'advanced'`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1006why, one step back
1006

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1007why, one step back
1007Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#ipc) option:

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1008–1014why, one step back
1008 - `json`: Uses `JSON.stringify()` and `JSON.parse()`.
1009 - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)10101011[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)10121013#### detached1014

Fix incorrect Markdown indentation in `readme.md` (#802)ehmickybefore adoption3bd96ba

lines 1015–1016why, one step back
1015Type: `boolean`\
1016Default: `false`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1017why, one step back
1017

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1018why, one step back
1018Prepare 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).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1019why, one step back
1019

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1020why, one step back
1020#### cleanup

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1021why, one step back
1021

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 1022–1023why, one step back
1022Type: `boolean`\
1023Default: `true`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1024why, one step back
1024

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 1025–1027why, one step back
1025Kill the subprocess when the current process exits unless either:
1026 - the subprocess is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)1027 - the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1028–1033why, one step back
1028
1029#### timeout10301031Type: `number`\1032Default: `0`1033

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1034why, one step back
1034If `timeout` is greater than `0`, the subprocess will be [terminated](#killsignal) if it runs for longer than that amount of milliseconds.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1035why, one step back
1035

Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf

line 1036why, one step back
1036#### cancelSignal

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1037why, one step back
1037

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1038why, one step back
1038Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1039why, one step back
1039

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1040why, one step back
1040You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1041why, one step back
1041

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1042why, one step back
1042When `AbortController.abort()` is called, [`.isCanceled`](#iscanceled) becomes `true`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1043why, one step back
1043

Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34

line 1044why, one step back
1044#### forceKillAfterDelay

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

lines 1045–1048why, one step back
1045
1046Type: `number | false`\1047Default: `5000`1048

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1049why, one step back
1049If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

lines 1050–1052why, one step back
1050
1051The grace period is 5 seconds by default. This feature can be disabled with `false`.1052

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1053why, one step back
1053This works when the subprocess is terminated by either:

Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf

line 1054why, one step back
1054- the [`cancelSignal`](#cancelsignal), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

lines 1055–1056why, one step back
1055- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments
1056

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1057why, one step back
1057This does not work when the subprocess is terminated by either:

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

lines 1058–1061why, one step back
1058- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with an argument
1059- calling [`process.kill(subprocess.pid)`](https://nodejs.org/api/process.html#processkillpid-signal)1060- sending a termination signal from another process1061

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1062why, one step back
1062Also, 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.

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

line 1063why, one step back
1063

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1064why, one step back
1064#### killSignal

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1065why, one step back
1065

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 1066–1067why, one step back
1066Type: `string | number`\
1067Default: `SIGTERM`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1068why, one step back
1068

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1069why, one step back
1069Signal used to terminate the subprocess when:

Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf

line 1070why, one step back
1070- using the [`cancelSignal`](#cancelsignal), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1071why, one step back
1071- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1072why, one step back
1072

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1073why, one step back
1073This can be either a name (like `"SIGTERM"`) or a number (like `9`).

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1074why, one step back
1074

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1075why, one step back
1075#### argv0

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1076why, one step back
1076

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1077why, one step back
1077Type: `string`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1078why, one step back
1078

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1079why, one step back
1079Explicitly set the value of `argv[0]` sent to the subprocess. This will be set to `file` if not specified.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1080why, one step back
1080

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1081why, one step back
1081#### uid

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1082why, one step back
1082

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1083why, one step back
1083Type: `number`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1084why, one step back
1084

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1085why, one step back
1085Sets the user identity of the subprocess.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1086why, one step back
1086

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1087why, one step back
1087#### gid

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1088why, one step back
1088

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1089why, one step back
1089Type: `number`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1090why, one step back
1090

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1091why, one step back
1091Sets the group identity of the subprocess.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1092why, one step back
1092

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1093why, one step back
1093#### windowsVerbatimArguments

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1094why, one step back
1094

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 1095–1096why, one step back
1095Type: `boolean`\
1096Default: `false`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1097why, one step back
1097

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1098why, one step back
1098If `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`.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1099why, one step back
1099

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1100why, one step back
1100#### windowsHide

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1101why, one step back
1101

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

lines 1102–1103why, one step back
1102Type: `boolean`\
1103Default: `true`

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 1104why, one step back
1104

Re-order options in `readme.md` (#800)ehmickybefore adoption97caf72

line 1105why, one step back
1105On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1106–1114why, one step back
1106
1107## Tips11081109### Redirect stdin/stdout/stderr to multiple destinations11101111The [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options can be an array of values.1112The following example redirects `stdout` to both the terminal and an `output.txt` file, while also retrieving its value programmatically.11131114```js

Allow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf

line 1115why, one step back
1115const {stdout} = await execa('npm', ['install'], {stdout: ['inherit', './output.txt', 'pipe']});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1116–1118why, one step back
1116console.log(stdout);
1117```1118

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1119why, one step back
1119When combining `inherit` with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1120–1133why, one step back
1120
1121### Redirect a Node.js stream from/to stdin/stdout/stderr11221123When 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.11241125```1126TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.1127```11281129This limitation can be worked around by passing either:1130 - a web stream ([`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream))1131 - `[nodeStream, 'pipe']` instead of `nodeStream`11321133```diff

Allow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf

lines 1134–1135why, one step back
1134- await execa(..., {stdout: nodeStream});
1135+ await execa(..., {stdout: [nodeStream, 'pipe']});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1136–1139why, one step back
1136```
11371138### Retry on error1139

Improve graceful exit (#714)ehmickybefore adoption5eeaab5

line 1140why, one step back
1140Safely handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1141–1152why, one step back
1141
1142```js1143import pRetry from 'p-retry';11441145const run = async () => {1146 const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']);1147 return results;1148};11491150console.log(await pRetry(run, {retries: 5}));1151```1152

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1153why, one step back
1153### Cancelling a subprocess

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1154–1158why, one step back
1154
1155```js1156import {execa} from 'execa';11571158const abortController = new AbortController();

Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf

line 1159why, one step back
1159const subprocess = execa('node', [], {cancelSignal: abortController.signal});

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1160–1187why, one step back
1160
1161setTimeout(() => {1162 abortController.abort();1163}, 1000);11641165try {1166 await subprocess;1167} catch (error) {1168 console.log(error.isTerminated); // true1169 console.log(error.isCanceled); // true1170}1171```11721173### Execute the current package's binary11741175Execa can be combined with [`get-bin-path`](https://github.com/ehmicky/get-bin-path) to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the `package.json` `bin` field is correctly set up.11761177```js1178import {getBinPath} from 'get-bin-path';11791180const binPath = await getBinPath();1181await execa(binPath);1182```11831184### Ensuring `all` output is interleaved11851186The `all` [stream](#all) and [string/`Uint8Array`](#all-1) properties are guaranteed to interleave [`stdout`](#stdout) and [`stderr`](#stderr).1187

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 1188why, one step back
1188However, for performance reasons, the subprocess might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This prevents proper interleaving.

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

lines 1189–1225why, one step back
1189
1190For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.11911192```js1193import {execa} from 'execa';11941195const {all} = await execa('node', ['example.js'], {all: true});1196console.log(all);1197```11981199```js1200// example.js1201console.log('1'); // writes to stdout1202console.error('2'); // writes to stderr1203console.log('3'); // writes to stdout1204```12051206This can be worked around by using `setTimeout()`.12071208```js1209import {setTimeout} from 'timers/promises';12101211console.log('1');1212console.error('2');1213await setTimeout(0);1214console.log('3');1215```12161217## Related12181219- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa1220- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version12211222## Maintainers12231224- [Sindre Sorhus](https://github.com/sindresorhus)1225- [@ehmicky](https://github.com/ehmicky)