readme.md
This file
Path
readme.md
944 lines · 35.3 KiB · Markdown
Last changed by
Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
History of this fileTake it
The walk stopped after 200 commits: lines older than f1eda9c point at it.
Improve the logo in dark mode (#505)ehmickybefore adoption7a8f5cd
lines 1–4why, one step back1<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>3.3.0ehmickybefore adoptionf1eda9c
lines 5–6why, one step back5<br>6Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
line 7why, one step back7[](https://codecov.io/gh/sindresorhus/execa)3.3.0ehmickybefore adoptionf1eda9c
lines 8–10why, one step back89> Process execution for humans10Meta tweaksSindre Sorhusbefore adoptiona228eda
lines 11–24why, one step back11<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>7.2.0Sindre Sorhusbefore adoptiondb58085
line 25why, one step back25 <a href="https://transloadit.com?utm_source=sindresorhus&utm_medium=referral&utm_campaign=sponsorship&utm_content=execa">Meta tweaksSindre Sorhusbefore adoptiona228eda
lines 26–40why, one step back26 <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>34 </p>35</div>3637---3839<br>403.3.0ehmickybefore adoptionf1eda9c
lines 41–44why, one step back41## Why4243This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with:44Improve the "Why" section in readme.md (#537)ehmickybefore adoption7c808f1
lines 45–49why, one step back45- [Promise interface](#execacommandcommand-options).46- [Scripts interface](#scripts-interface), like `zx`.47- Improved [Windows support](https://github.com/IndigoUnited/node-cross-spawn#why), including [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries.48- Executes [locally installed binaries](#preferlocal) without `npx`.49- [Cleans up](#cleanup) child processes when the parent process ends.Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 50why, one step back50- 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
lines 51–52why, one step back51- [Transform](docs/transform.md) `stdin`/`stdout`/`stderr` with simple functions.52- Iterate over [each text line](docs/transform.md#binary-data) output by the process.Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 53why, one step back53- [Fail-safe process termination](#forcekillafterdelay).Improve the "Why" section in readme.md (#537)ehmickybefore adoption7c808f1
line 54why, one step back54- Get [interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal.3.3.0ehmickybefore adoptionf1eda9c
line 55why, one step back55- [Strips the final newline](#stripfinalnewline) from the output so you don't have to do `stdout.trim()`.Improve the "Why" section in readme.md (#537)ehmickybefore adoption7c808f1
lines 56–58why, one step back56- Convenience methods to pipe processes' [input](#input) and [output](#redirect-output-to-a-file).57- Can specify file and arguments [as a single string](#execacommandcommand-options) without a shell.58- [Verbose mode](#verbose-mode) for debugging.3.3.0ehmickybefore adoptionf1eda9c
line 59why, one step back59- More descriptive errors.Improve the "Why" section in readme.md (#537)ehmickybefore adoption7c808f1
line 60why, one step back60- Higher max buffer: 100 MB instead of 1 MB.3.3.0ehmickybefore adoptionf1eda9c
lines 61–63why, one step back6162## Install63Minor tweaksSindre Sorhusbefore adoption244e87a
lines 64–65why, one step back64```sh65npm install execa3.3.0ehmickybefore adoptionf1eda9c
lines 66–69why, one step back66```6768## Usage69Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 70–71why, one step back70### Promise interface713.3.0ehmickybefore adoptionf1eda9c
line 72why, one step back72```jsRequire Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 73why, one step back73import {execa} from 'execa';3.3.0ehmickybefore adoptionf1eda9c
line 74why, one step back74Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 75–77why, one step back75const {stdout} = await execa('echo', ['unicorns']);76console.log(stdout);77//=> 'unicorns'3.3.0ehmickybefore adoptionf1eda9c
lines 78–79why, one step back78```79Add more documentation for `$` (#533)ehmickybefore adoption9bcfa95
line 80why, one step back80### Scripts interfaceAdd `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 81why, one step back81Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 82why, one step back82For more information about Execa scripts, please see [this page](docs/scripts.md).Add more documentation for `$` (#533)ehmickybefore adoption9bcfa95
line 83why, one step back83Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
lines 84–88why, one step back84#### Basic8586```js87import {$} from 'execa';88Fix semicolons and spaces in documentation examples (#547)ehmickybefore adoptionb260fa4
lines 89–90why, one step back89const branch = await $`git branch --show-current`;90await $`dep deploy --branch=${branch}`;Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 91why, one step back91```Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 92why, one step back92Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 93–97why, one step back93#### Multiple arguments9495```js96import {$} from 'execa';97Fix semicolons and spaces in documentation examples (#547)ehmickybefore adoptionb260fa4
line 98why, one step back98const args = ['unicorns', '&', 'rainbows!'];Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 99why, one step back99const {stdout} = await $`echo ${args}`;Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 100why, one step back100console.log(stdout);Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 101why, one step back101//=> 'unicorns & rainbows!'Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
lines 102–112why, one step back102```103104#### With options105106```js107import {$} from 'execa';108109await $({stdio: 'inherit'})`echo unicorns`;110//=> 'unicorns'111```112Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 113why, one step back113#### Shared optionsAdd `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
lines 114–122why, one step back114115```js116import {$} from 'execa';117118const $$ = $({stdio: 'inherit'});119120await $$`echo unicorns`;121//=> 'unicorns'122Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 123why, one step back123await $$`echo rainbows`;Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
lines 124–126why, one step back124//=> 'rainbows'125```126Add `verbose` option (#532)ehmickybefore adoption69ce814
lines 127–140why, one step back127#### Verbose mode128129```sh130> node file.js131unicorns132rainbows133134> NODE_DEBUG=execa node file.js135[16:50:03.305] echo unicorns136unicorns137[16:50:03.308] echo rainbows138rainbows139```140Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 141why, one step back141### Input/output3.3.0ehmickybefore adoptionf1eda9c
line 142why, one step back142Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 143–144why, one step back143#### Redirect output to a file1443.3.0ehmickybefore adoptionf1eda9c
line 145why, one step back145```jsRequire Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 146why, one step back146import {execa} from 'execa';3.3.0ehmickybefore adoptionf1eda9c
line 147why, one step back147Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
line 148why, one step back148// Similar to `echo unicorns > stdout.txt` in BashFix documentation about piping from stdin (#536)ehmickybefore adoption4857cc4
line 149why, one step back149await execa('echo', ['unicorns']).pipeStdout('stdout.txt');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 150–151why, one step back150151// Similar to `echo unicorns 2> stdout.txt` in BashFix documentation about piping from stdin (#536)ehmickybefore adoption4857cc4
line 152why, one step back152await execa('echo', ['unicorns']).pipeStderr('stderr.txt');Add `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 153–154why, one step back153154// Similar to `echo unicorns &> stdout.txt` in BashFix semicolons and spaces in documentation examples (#547)ehmickybefore adoptionb260fa4
line 155why, one step back155await execa('echo', ['unicorns'], {all: true}).pipeAll('all.txt');3.3.0ehmickybefore adoptionf1eda9c
lines 156–157why, one step back156```157Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 158why, one step back158#### Redirect input from a fileFix documentation about piping from stdin (#536)ehmickybefore adoption4857cc4
lines 159–163why, one step back159160```js161import {execa} from 'execa';162163// Similar to `cat < stdin.txt` in BashFix semicolons and spaces in documentation examples (#547)ehmickybefore adoptionb260fa4
line 164why, one step back164const {stdout} = await execa('cat', {inputFile: 'stdin.txt'});Fix documentation about piping from stdin (#536)ehmickybefore adoption4857cc4
lines 165–168why, one step back165console.log(stdout);166//=> 'unicorns'167```168Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 169why, one step back169#### Save and pipe output from a child processAdd `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 170–179why, one step back170171```js172import {execa} from 'execa';173174const {stdout} = await execa('echo', ['unicorns']).pipeStdout(process.stdout);175// Prints `unicorns`176console.log(stdout);177// Also returns 'unicorns'178```179Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
line 180why, one step back180#### Pipe multiple processesAdd `pipeStdout()`-related methods (#531)ehmickybefore adoption06287c8
lines 181–190why, one step back181182```js183import {execa} from 'execa';184185// Similar to `echo unicorns | cat` in Bash186const {stdout} = await execa('echo', ['unicorns']).pipeStdout(execa('cat'));187console.log(stdout);188//=> 'unicorns'189```1903.3.0ehmickybefore adoptionf1eda9c
lines 191–193why, one step back191### Handling Errors192193```jsRequire Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 194why, one step back194import {execa} from 'execa';3.3.0ehmickybefore adoptionf1eda9c
line 195why, one step back195Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 196–217why, one step back196// Catching an error197try {198 await execa('unknown', ['command']);199} catch (error) {200 console.log(error);201 /*202 {203 message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',204 errno: -2,205 code: 'ENOENT',206 syscall: 'spawn unknown',207 path: 'unknown',208 spawnargs: ['command'],209 originalMessage: 'spawn unknown ENOENT',210 shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',211 command: 'unknown command',212 escapedCommand: 'unknown command',213 stdout: '',214 stderr: '',215 failed: true,216 timedOut: false,217 isCanceled: false,Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 218why, one step back218 isTerminated: false3.3.0ehmickybefore adoptionf1eda9c
line 219why, one step back219 }Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 220–221why, one step back220 */221}3.3.0ehmickybefore adoptionf1eda9c
lines 222–225why, one step back222```223224## API225Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 226why, one step back226### Methods3.3.0ehmickybefore adoptionf1eda9c
line 227why, one step back227Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 228why, one step back228#### execa(file, arguments?, options?)3.3.0ehmickybefore adoptionf1eda9c
line 229why, one step back229Allow the first argument of `execa()` to be a file URL (#631)ehmickybefore adoption3bbd8ae
line 230why, one step back230Executes a command using `file ...arguments`. `file` is a string or a file URL. `arguments` are an array of strings. Returns a [`childProcess`](#childprocess).3.3.0ehmickybefore adoptionf1eda9c
line 231why, one step back231Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 232why, one step back232Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.3.3.0ehmickybefore adoptionf1eda9c
line 233why, one step back233Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 234why, one step back234This is the preferred method when executing single commands.Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 235why, one step back235Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 236why, one step back236#### execaNode(scriptPath, arguments?, options?)Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 237why, one step back237Allow the first argument of `execa()` to be a file URL (#631)ehmickybefore adoption3bbd8ae
line 238why, one step back238Executes a Node.js file using `node scriptPath ...arguments`. `file` is a string or a file URL. `arguments` are an array of strings. Returns a [`childProcess`](#childprocess).Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 239why, one step back239Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 240why, one step back240Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.Allow `execa` return values in `$` template expressions (#528)Aaron Casanovabefore adoption58ea251
line 241why, one step back241Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 242why, one step back242This is the preferred method when executing Node.js files.Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 243why, one step back243Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 244why, one step back244Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options):Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 245–246why, one step back245- the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options.246- the [`shell`](#shell) option cannot be usedAdd `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 247why, one step back247- an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio-1)Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 248why, one step back248Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 249why, one step back249#### $\`command\`Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 250why, one step back250Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 251why, one step back251Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).Add `$` tagged templates API (#510)Aaron Casanovabefore adoptioneae327c
line 252why, one step back252Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 253why, one step back253Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.3.3.0ehmickybefore adoptionf1eda9c
line 254why, one step back254Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 255why, one step back255This is the preferred method when executing multiple commands in a script file.3.3.0ehmickybefore adoptionf1eda9c
line 256why, one step back256Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 257why, one step back257The `command` string can inject any `${value}` with the following types: string, number, [`childProcess`](#childprocess) or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used.3.3.0ehmickybefore adoptionf1eda9c
line 258why, one step back258Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 259why, one step back259For more information, please see [this section](#scripts-interface) and [this page](docs/scripts.md).3.3.0ehmickybefore adoptionf1eda9c
line 260why, one step back260Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 261why, one step back261#### $(options)3.3.0ehmickybefore adoptionf1eda9c
line 262why, one step back262Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 263why, one step back263Returns a new instance of [`$`](#command) but with different default `options`. Consecutive calls are merged to previous ones.3.3.0ehmickybefore adoptionf1eda9c
line 264why, one step back264Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 265why, one step back265This can be used to either:Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 266–267why, one step back266- Set options for a specific command: `` $(options)`command` ``267- Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand`; ``3.3.0ehmickybefore adoptionf1eda9c
line 268why, one step back268Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 269why, one step back269#### execaCommand(command, options?)Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
line 270why, one step back270Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 271–280why, one step back271Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).272273Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.274275This is the preferred method when executing a user-supplied `command` string, such as in a REPL.276277### execaSync(file, arguments?, options?)278279Same as [`execa()`](#execacommandcommand-options) but synchronous.280Allow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf
line 281why, one step back281Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
line 282why, one step back282Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 283–285why, one step back283Returns or throws a [`childProcessResult`](#childProcessResult).284285### $.sync\`command\`Add `$.s` as an alias for `$.sync` (#594)ehmickybefore adoptionb719fb0
line 286why, one step back286### $.s\`command\`Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 287–289why, one step back287288Same as [$\`command\`](#command) but synchronous.289Allow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf
line 290why, one step back290Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
line 291why, one step back291Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 292–297why, one step back292Returns or throws a [`childProcessResult`](#childProcessResult).293294### execaCommandSync(command, options?)295296Same as [`execaCommand()`](#execacommand-command-options) but synchronous.297Allow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf
line 298why, one step back298Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
line 299why, one step back299Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
lines 300–305why, one step back300Returns or throws a [`childProcessResult`](#childProcessResult).301302### Shell syntax303304For 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.305Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
lines 306–307why, one step back306### childProcess307Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a
line 308why, one step back308The return value of all [asynchronous methods](#methods) is both:Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 309–310why, one step back309- a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult).310- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties.Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
lines 311–315why, one step back311312#### all313314Type: `ReadableStream | undefined`315Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
line 316why, one step back316Stream [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).Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
lines 317–318why, one step back317318This is `undefined` if either:Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 319–320why, one step back319- the [`all` option](#all-2) is `false` (the default value)320- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
lines 321–324why, one step back321322#### pipeStdout(target)323324[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be:Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 325–327why, one step back325- Another [`execa()` return value](#pipe-multiple-processes)326- A [writable stream](#save-and-pipe-output-from-a-child-process)327- A [file path string](#redirect-output-to-a-file)Move the `childProcess` section in the readme.md (#539)ehmickybefore adoption4993dcb
lines 328–343why, one step back328329If the `target` is another [`execa()` return value](#execacommandcommand-options), it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the [final result](#childprocessresult).330331The [`stdout` option](#stdout-1) must be kept as `pipe`, its default value.332333#### pipeStderr(target)334335Like [`pipeStdout()`](#pipestdouttarget) but piping the child process's `stderr` instead.336337The [`stderr` option](#stderr-1) must be kept as `pipe`, its default value.338339#### pipeAll(target)340341Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget).342343Either the [`stdout` option](#stdout-1) or the [`stderr` option](#stderr-1) must be kept as `pipe`, their default value. Also, the [`all` option](#all-2) must be set to `true`.3.3.0ehmickybefore adoptionf1eda9c
lines 344–352why, one step back344345### childProcessResult346347Type: `object`348349Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.350351The child process [fails](#failed) when:352- its [exit code](#exitcode) is not `0`Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 353why, one step back353- it was [terminated](#isterminated) with a [signal](#signal)3.3.0ehmickybefore adoptionf1eda9c
lines 354–361why, one step back354- [timing out](#timedout)355- [being canceled](#iscanceled)356- there's not enough memory or there are already too many child processes357358#### command359360Type: `string`361Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
lines 362–363why, one step back362The file and arguments that were run, for logging purposes.363Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 364why, one step back364This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
lines 365–369why, one step back365366#### escapedCommand367368Type: `string`369Fix anchor in readme.md (#530)ehmickybefore adoption2c58762
line 370why, one step back370Same as [`command`](#command-1) but escaped.Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
lines 371–372why, one step back371372This is meant to be copy and pasted into a shell, for debugging purposes.Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 373why, one step back373Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).3.3.0ehmickybefore adoptionf1eda9c
lines 374–376why, one step back374375#### exitCode376Document and type `exitCode` being `undefined` (#680)ehmickybefore adoption95e5754
line 377why, one step back377Type: `number | undefined`3.3.0ehmickybefore adoptionf1eda9c
lines 378–379why, one step back378379The numeric exit code of the process that was run.Document and type `exitCode` being `undefined` (#680)ehmickybefore adoption95e5754
lines 380–381why, one step back380381This is `undefined` when the process could not be spawned or was terminated by a [signal](#signal-1).3.3.0ehmickybefore adoptionf1eda9c
lines 382–384why, one step back382383#### stdout384Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 385why, one step back385Type: `string | Uint8Array | unknown[] | undefined`3.3.0ehmickybefore adoptionf1eda9c
line 386why, one step back386Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 387why, one step back387The output of the process on `stdout`.3.3.0ehmickybefore adoptionf1eda9c
line 388why, one step back388Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 389why, one step back389This is `undefined` if the [`stdout`](#stdout-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 390why, one step back3903.3.0ehmickybefore adoptionf1eda9c
lines 391–392why, one step back391#### stderr392Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 393why, one step back393Type: `string | Uint8Array | unknown[] | undefined`3.3.0ehmickybefore adoptionf1eda9c
line 394why, one step back394Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 395why, one step back395The output of the process on `stderr`.3.3.0ehmickybefore adoptionf1eda9c
line 396why, one step back396Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 397why, one step back397This is `undefined` if the [`stderr`](#stderr-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 398why, one step back3983.3.0ehmickybefore adoptionf1eda9c
lines 399–400why, one step back399#### all400Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 401why, one step back401Type: `string | Uint8Array | unknown[] | undefined`3.3.0ehmickybefore adoptionf1eda9c
line 402why, one step back402Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
line 403why, one step back403The output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).3.3.0ehmickybefore adoptionf1eda9c
lines 404–405why, one step back404405This is `undefined` if either:Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 406–407why, one step back406- the [`all` option](#all-2) is `false` (the default value)407- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)3.3.0ehmickybefore adoptionf1eda9c
line 408why, one step back408Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 409–410why, one step back409This is an array if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).410Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 411–412why, one step back411#### stdio412Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 413why, one step back413Type: `Array<string | Uint8Array | unknown[] | undefined>`Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 414–416why, one step back414415The output of the process on [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [other file descriptors](#stdio-1).416Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 417why, one step back417Items are `undefined` when their corresponding [`stdio`](#stdio-1) option is set to [`'inherit'`, `'ipc'`, `'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 418why, one step back4183.3.0ehmickybefore adoptionf1eda9c
lines 419–434why, one step back419#### failed420421Type: `boolean`422423Whether the process failed to run.424425#### timedOut426427Type: `boolean`428429Whether the process timed out.430431#### isCanceled432433Type: `boolean`434Remove `.cancel()` method (#711)ehmickybefore adoption16e5fd6
line 435why, one step back435Whether the process was canceled using the [`signal`](#signal-1) option.Support `AbortController` (#490)Gyubongbefore adoptionc6e791a
line 436why, one step back436Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 437why, one step back437#### isTerminated3.3.0ehmickybefore adoptionf1eda9c
lines 438–440why, one step back438439Type: `boolean`440Improve process termination (#724)ehmickybefore adoption1c48d37
lines 441–443why, one step back441Whether the process was terminated by a signal (like `SIGTERM`) sent by either:442- The current process.443- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).3.3.0ehmickybefore adoptionf1eda9c
lines 444–448why, one step back444445#### signal446447Type: `string | undefined`448Improve process termination (#724)ehmickybefore adoption1c48d37
lines 449–451why, one step back449The name of the signal (like `SIGTERM`) that terminated the process, sent by either:450- The current process.451- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).3.3.0ehmickybefore adoptionf1eda9c
lines 452–462why, one step back452453If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.454455#### signalDescription456457Type: `string | undefined`458459A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.460461If a signal terminated the process, 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.462Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
lines 463–468why, one step back463#### cwd464465Type: `string`466467The `cwd` of the command if provided in the [command options](#cwd-1). Otherwise it is `process.cwd()`.468Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 469–474why, one step back469#### message470471Type: `string`472473Error message when the child process failed to run. In addition to the [underlying error message](#originalMessage), it also contains some information related to why the child process errored.474Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 475why, one step back475The child process [`stderr`](#stderr), [`stdout`](#stdout) and other [file descriptors' output](#stdio) are appended to the end, separated with newlines and not interleaved.Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 476–480why, one step back476477#### shortMessage478479Type: `string`480Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 481why, one step back481This is the same as the [`message` property](#message) except it does not include the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio).Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 482why, one step back4823.3.0ehmickybefore adoptionf1eda9c
lines 483–486why, one step back483#### originalMessage484485Type: `string | undefined`486Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 487why, one step back487Original error message. This is the same as the `message` property excluding the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio) and some additional information added by Execa.3.3.0ehmickybefore adoptionf1eda9c
line 488why, one step back488Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 489why, one step back489This is `undefined` unless the child process exited due to an `error` event or a timeout.3.3.0ehmickybefore adoptionf1eda9c
lines 490–496why, one step back490491### options492493Type: `object`494495#### cleanup496Meta tweaksSindre Sorhusbefore adoption4093556
line 497why, one step back497Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 498–505why, one step back498Default: `true`499500Kill the spawned process when the parent process exits unless either:501 - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)502 - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit503504#### preferLocal505Meta tweaksSindre Sorhusbefore adoption4093556
line 506why, one step back506Type: `boolean`\Fix default value of `stdin` with `$` (#550)ehmickybefore adoption6fe7e51
line 507why, one step back507Default: `true` with [`$`](#command), `false` otherwise3.3.0ehmickybefore adoptionf1eda9c
line 508why, one step back508Meta tweaksSindre Sorhusbefore adoption4093556
line 509why, one step back509Prefer locally installed binaries when looking for a binary to execute.\3.3.0ehmickybefore adoptionf1eda9c
lines 510–513why, one step back510If you `$ npm install foo`, you can then `execa('foo')`.511512#### localDir513Allow `cwd` and `localDir` options to be URLs (#492)ehmickybefore adoption93ab929
line 514why, one step back514Type: `string | URL`\3.3.0ehmickybefore adoptionf1eda9c
lines 515–520why, one step back515Default: `process.cwd()`516517Preferred path to find locally installed binaries in (use with `preferLocal`).518519#### execPath520Allow the `execPath` option to be a file URL (#633)ehmickybefore adoptionb495146
line 521why, one step back521Type: `string | URL`\Meta tweaksSindre Sorhusbefore adoption4093556
line 522why, one step back522Default: `process.execPath` (Current Node.js executable)3.3.0ehmickybefore adoptionf1eda9c
lines 523–533why, one step back523524Path to the Node.js executable to use in child processes.525526This can be either an absolute path or a path relative to the [`cwd` option](#cwd).527528Requires [`preferLocal`](#preferlocal) to be `true`.529530For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.531532#### buffer533Meta tweaksSindre Sorhusbefore adoption4093556
line 534why, one step back534Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 535–538why, one step back535Default: `true`536537Buffer the output from the spawned process. When set to `false`, you must read the output of [`stdout`](#stdout-1) and [`stderr`](#stderr-1) (or [`all`](#all) if the [`all`](#all-2) option is `true`). Otherwise the returned promise will not be resolved/rejected.538Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 539why, one step back539If the spawned process fails, [`error.stdout`](#stdout), [`error.stderr`](#stderr), [`error.all`](#all) and [`error.stdio`](#stdio) will contain the buffered data.3.3.0ehmickybefore adoptionf1eda9c
lines 540–542why, one step back540541#### input542Require Node.js 18Sindre Sorhusbefore adoption834e372
line 543why, one step back543Type: `string | Uint8Array | stream.Readable`3.3.0ehmickybefore adoptionf1eda9c
line 544why, one step back544Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
line 545why, one step back545Write some input to the child process' `stdin`.Add `inputFile` option (#542)ehmickybefore adoption0726126
line 546why, one step back546Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 547why, one step back547See also the [`inputFile`](#inputfile) and [`stdin`](#stdin) options.Add `inputFile` option (#542)ehmickybefore adoption0726126
lines 548–550why, one step back548549#### inputFile550Add support for file URLs with the `inputFile` option (#630)ehmickybefore adoptionbe739e7
line 551why, one step back551Type: `string | URL`Add `inputFile` option (#542)ehmickybefore adoption0726126
line 552why, one step back552Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 553why, one step back553Use a file as input to the child process' `stdin`.Add `inputFile` option (#542)ehmickybefore adoption0726126
line 554why, one step back554Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 555why, one step back555See also the [`input`](#input) and [`stdin`](#stdin) options.3.3.0ehmickybefore adoptionf1eda9c
lines 556–558why, one step back556557#### stdin558Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 559why, one step back559Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array> | AsyncGeneratorFunction<string | Uint8Array>` (or a tuple of those types)\Fix default value of `stdin` with `$` (#550)ehmickybefore adoption6fe7e51
line 560why, one step back560Default: `inherit` with [`$`](#command), `pipe` otherwise3.3.0ehmickybefore adoptionf1eda9c
line 561why, one step back561Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 562–568why, one step back562[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard input. This can be:563- `'pipe'`: Sets [`childProcess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.564- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.565- `'ignore'`: Do not use `stdin`.566- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.567- `'inherit'`: Re-use the current process' `stdin`.568- an integer: Re-use a specific file descriptor from the current process.Document how to pass a Node.js stream to stdin/stdout/stderr (#644)ehmickybefore adoption2500696
line 569why, one step back569- a [Node.js `Readable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 570why, one step back570- `{ file: 'path' }` object.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
lines 571–573why, one step back571- a file URL.572- a web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).573- 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 574why, one step back574- an `Uint8Array`.Allow `stdin` to be a sync/async iterable (#604)ehmickybefore adoptionec380db
line 575why, one step back575Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 576–577why, one step back576This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.577Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 578–579why, one step back578This can also be an async generator function to transform the input. [Learn more.](docs/transform.md)5793.3.0ehmickybefore adoptionf1eda9c
lines 580–581why, one step back580#### stdout581Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 582why, one step back582Type: `string | number | stream.Writable | WritableStream | URL | AsyncGeneratorFunction<string | Uint8Array>` (or a tuple of those types)\3.3.0ehmickybefore adoptionf1eda9c
lines 583–584why, one step back583Default: `pipe`584Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 585why, one step back585[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard output. This can be:Improve documentation of `pipe` option (#637)ehmickybefore adoption9632b38
line 586why, one step back586- `'pipe'`: Sets [`childProcessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`childProcess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 587–591why, one step back587- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.588- `'ignore'`: Do not use `stdout`.589- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.590- `'inherit'`: Re-use the current process' `stdout`.591- an integer: Re-use a specific file descriptor from the current process.Document how to pass a Node.js stream to stdin/stdout/stderr (#644)ehmickybefore adoption2500696
line 592why, one step back592- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 593why, one step back593- `{ file: 'path' }` object.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
lines 594–595why, one step back594- a file URL.595- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).3.3.0ehmickybefore adoptionf1eda9c
line 596why, one step back596Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 597–598why, one step back597This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.598Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 599–600why, one step back599This can also be an async generator function to transform the output. [Learn more.](docs/transform.md)6003.3.0ehmickybefore adoptionf1eda9c
lines 601–602why, one step back601#### stderr602Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 603why, one step back603Type: `string | number | stream.Writable | WritableStream | URL | AsyncGeneratorFunction<string | Uint8Array>` (or a tuple of those types)`\3.3.0ehmickybefore adoptionf1eda9c
lines 604–605why, one step back604Default: `pipe`605Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 606why, one step back606[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the child process' standard error. This can be:Improve documentation of `pipe` option (#637)ehmickybefore adoption9632b38
line 607why, one step back607- `'pipe'`: Sets [`childProcessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`childProcess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 608–612why, one step back608- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.609- `'ignore'`: Do not use `stderr`.610- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.611- `'inherit'`: Re-use the current process' `stderr`.612- an integer: Re-use a specific file descriptor from the current process.Document how to pass a Node.js stream to stdin/stdout/stderr (#644)ehmickybefore adoption2500696
line 613why, one step back613- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 614why, one step back614- `{ file: 'path' }` object.Improve documentation of synchronous methods (#669)ehmickybefore adoptionb11cbcd
lines 615–616why, one step back615- a file URL.616- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).3.3.0ehmickybefore adoptionf1eda9c
line 617why, one step back617Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 618–619why, one step back618This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.619Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 620–621why, one step back620This can also be an async generator function to transform the output. [Learn more.](docs/transform.md)621Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 622–623why, one step back622#### stdio623Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 624why, one step back624Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Uint8Array | Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array> | AsyncGeneratorFunction<string | Uint8Array>>` (or a tuple of those types)\Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
lines 625–626why, one step back625Default: `pipe`626Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
line 627why, one step back627Like 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'}`.Improve documentation of `stdin`, `stdout`, `stderr` and `stdio` (#626)ehmickybefore adoptionc405105
line 628why, one step back628Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 629–632why, one step back629A single string can be used as a shortcut. For example, `{stdio: 'pipe'}` is the same as `{stdin: 'pipe', stdout: 'pipe', stderr: 'pipe'}`.630631The array can have more than 3 items, to create additional file descriptors beyond `stdin`/`stdout`/`stderr`. For example, `{stdio: ['pipe', 'pipe', 'pipe', 'ipc']}` sets a fourth file descriptor `'ipc'`.6323.3.0ehmickybefore adoptionf1eda9c
lines 633–634why, one step back633#### all634Meta tweaksSindre Sorhusbefore adoption4093556
line 635why, one step back635Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 636–637why, one step back636Default: `false`637Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
line 638why, one step back638Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).3.3.0ehmickybefore adoptionf1eda9c
lines 639–641why, one step back639640#### reject641Meta tweaksSindre Sorhusbefore adoption4093556
line 642why, one step back642Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 643–648why, one step back643Default: `true`644645Setting this to `false` resolves the promise with the error instead of rejecting it.646647#### stripFinalNewline648Meta tweaksSindre Sorhusbefore adoption4093556
line 649why, one step back649Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 650–655why, one step back650Default: `true`651652Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.653654#### extendEnv655Meta tweaksSindre Sorhusbefore adoption4093556
line 656why, one step back656Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 657–658why, one step back657Default: `true`658Improve documentation of the `extendEnv` and `env` options (#710)ehmickybefore adoption163d6ee
lines 659–660why, one step back659If `true`, the child process uses both the [`env` option](#env) and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).660If `false`, only the `env` option is used, not `process.env`.3.3.0ehmickybefore adoptionf1eda9c
lines 661–667why, one step back661662---663664Execa also accepts the below options which are the same as the options 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)665666#### cwd667Allow `cwd` and `localDir` options to be URLs (#492)ehmickybefore adoption93ab929
line 668why, one step back668Type: `string | URL`\3.3.0ehmickybefore adoptionf1eda9c
lines 669–671why, one step back669Default: `process.cwd()`670671Current working directory of the child process.Allow `cwd` and `localDir` options to be URLs (#492)ehmickybefore adoption93ab929
line 672why, one step back6723.3.0ehmickybefore adoptionf1eda9c
lines 673–674why, one step back673#### env674Meta tweaksSindre Sorhusbefore adoption4093556
line 675why, one step back675Type: `object`\3.3.0ehmickybefore adoptionf1eda9c
lines 676–677why, one step back676Default: `process.env`677Improve documentation of the `extendEnv` and `env` options (#710)ehmickybefore adoption163d6ee
lines 678–680why, one step back678Environment key-value pairs.679680Unless the [`extendEnv` option](#extendenv) is `false`, the child process also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).3.3.0ehmickybefore adoptionf1eda9c
lines 681–687why, one step back681682#### argv0683684Type: `string`685686Explicitly set the value of `argv[0]` sent to the child process. This will be set to `file` if not specified.687Add `serialization` option (#392)ehmickybefore adoption31ac967
lines 688–689why, one step back688#### serialization689Meta tweaksSindre Sorhusbefore adoption4093556
line 690why, one step back690Type: `string`\Add `serialization` option (#392)ehmickybefore adoption31ac967
lines 691–692why, one step back691Default: `'json'`692Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 693why, one step back693Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio-1) option or [`execaNode()`](#execanodescriptpath-arguments-options):Add `serialization` option (#392)ehmickybefore adoption31ac967
lines 694–698why, one step back694 - `json`: Uses `JSON.stringify()` and `JSON.parse()`.695 - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)696697[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)6983.3.0ehmickybefore adoptionf1eda9c
lines 699–718why, one step back699#### detached700701Type: `boolean`702703Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).704705#### uid706707Type: `number`708709Sets the user identity of the process.710711#### gid712713Type: `number`714715Sets the group identity of the process.716717#### shell718Allow `shell` option to be a file URL (#635)ehmickybefore adoption189d486
line 719why, one step back719Type: `boolean | string | URL`\3.3.0ehmickybefore adoptionf1eda9c
lines 720–730why, one step back720Default: `false`721722If `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.723724We recommend against using this option since it is:725- not cross-platform, encouraging shell-specific syntax.726- slower, because of the additional shell interpretation.727- unsafe, potentially allowing command injection.728729#### encoding730Make `buffer` encoding option return `Uint8Array` instead of `Buffer` (#586)Youngbefore adoption1afeb81
line 731why, one step back731Type: `string`\3.3.0ehmickybefore adoptionf1eda9c
lines 732–733why, one step back732Default: `utf8`733Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 734why, one step back734Specify the character encoding used to decode the [`stdout`](#stdout), [`stderr`](#stderr) and [`stdio`](#stdio) output. If set to `'buffer'`, then `stdout`, `stderr` and `stdio` will be `Uint8Array`s instead of strings.3.3.0ehmickybefore adoptionf1eda9c
lines 735–737why, one step back735736#### timeout737Meta tweaksSindre Sorhusbefore adoption4093556
line 738why, one step back738Type: `number`\3.3.0ehmickybefore adoptionf1eda9c
lines 739–740why, one step back739Default: `0`740Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
line 741why, one step back741If `timeout`` is greater than `0`, the child process will be [terminated](#killsignal) if it runs for longer than that amount of milliseconds.3.3.0ehmickybefore adoptionf1eda9c
lines 742–744why, one step back742743#### maxBuffer744Meta tweaksSindre Sorhusbefore adoption4093556
line 745why, one step back745Type: `number`\3.3.0ehmickybefore adoptionf1eda9c
lines 746–747why, one step back746Default: `100_000_000` (100 MB)747Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 748why, one step back748Largest amount of data in bytes allowed on [`stdout`](#stdout), [`stderr`](#stderr) and [`stdio`](#stdio).3.3.0ehmickybefore adoptionf1eda9c
lines 749–751why, one step back749750#### killSignal751Meta tweaksSindre Sorhusbefore adoption4093556
line 752why, one step back752Type: `string | number`\3.3.0ehmickybefore adoptionf1eda9c
lines 753–754why, one step back753Default: `SIGTERM`754Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
lines 755–759why, one step back755Signal used to terminate the child process when:756- using the [`signal`](#signal-1), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option757- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments758759This can be either a name (like `"SIGTERM"`) or a number (like `9`).Support `AbortController` (#490)Gyubongbefore adoptionc6e791a
line 760why, one step back760Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 761why, one step back761#### forceKillAfterDelayImprove graceful exit (#714)ehmickybefore adoption5eeaab5
lines 762–780why, one step back762763Type: `number | false`\764Default: `5000`765766If the child process is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).767768The grace period is 5 seconds by default. This feature can be disabled with `false`.769770This works when the child process is terminated by either:771- the [`signal`](#signal-1), [`timeout`](#timeout), [`maxBuffer`](#maxbuffer) or [`cleanup`](#cleanup) option772- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments773774This does not work when the child process is terminated by either:775- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with an argument776- calling [`process.kill(subprocess.pid)`](https://nodejs.org/api/process.html#processkillpid-signal)777- sending a termination signal from another process778779Also, 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 process immediately. Other packages (such as [`taskkill`](https://github.com/sindresorhus/taskkill)) can be used to achieve fail-safe termination on Windows.780Support `AbortController` (#490)Gyubongbefore adoptionc6e791a
lines 781–786why, one step back781#### signal782783Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)784785You can abort the spawned process using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).786Fix documentation typo (#568)Gray Zhangbefore adoptionf31fbdb
line 787why, one step back787When `AbortController.abort()` is called, [`.isCanceled`](#iscanceled) becomes `true`.Support `AbortController` (#490)Gyubongbefore adoptionc6e791a
line 788why, one step back7883.3.0ehmickybefore adoptionf1eda9c
lines 789–790why, one step back789#### windowsVerbatimArguments790Meta tweaksSindre Sorhusbefore adoption4093556
line 791why, one step back791Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 792–797why, one step back792Default: `false`793794If `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`.795796#### windowsHide797Meta tweaksSindre Sorhusbefore adoption4093556
line 798why, one step back798Type: `boolean`\3.3.0ehmickybefore adoptionf1eda9c
lines 799–801why, one step back799Default: `true`800801On 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.Add `verbose` option (#532)ehmickybefore adoption69ce814
lines 802–810why, one step back802803#### verbose804805Type: `boolean`\806Default: `false`807808[Print each command](#verbose-mode) on `stderr` before executing it.809810This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process.3.3.0ehmickybefore adoptionf1eda9c
line 811why, one step back811Meta tweaksSindre Sorhusbefore adoption4093556
line 812why, one step back812#### nodePath *(For `.node()` only)*3.3.0ehmickybefore adoptionf1eda9c
line 813why, one step back813Allow `nodePath` option to be a file URL (#632)ehmickybefore adoption77e1477
line 814why, one step back814Type: `string | URL`\3.3.0ehmickybefore adoptionf1eda9c
lines 815–818why, one step back815Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath)816817Node.js executable used to create the child process.818Meta tweaksSindre Sorhusbefore adoption4093556
line 819why, one step back819#### nodeOptions *(For `.node()` only)*3.3.0ehmickybefore adoptionf1eda9c
line 820why, one step back820Meta tweaksSindre Sorhusbefore adoption4093556
line 821why, one step back821Type: `string[]`\3.3.0ehmickybefore adoptionf1eda9c
lines 822–826why, one step back822Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv)823824List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.825826## TipsAllow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 827–833why, one step back827828### Redirect stdin/stdout/stderr to multiple destinations829830The [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options can be an array of values.831The following example redirects `stdout` to both the terminal and an `output.txt` file, while also retrieving its value programmatically.832833```jsAllow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf
line 834why, one step back834const {stdout} = await execa('npm', ['install'], {stdout: ['inherit', './output.txt', 'pipe']});Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 835–838why, one step back835console.log(stdout);836```837838When combining `inherit` with other values, please note that the child process will not be an interactive TTY, even if the parent process is one.Document how to pass a Node.js stream to stdin/stdout/stderr (#644)ehmickybefore adoption2500696
lines 839–852why, one step back839840### Redirect a Node.js stream from/to stdin/stdout/stderr841842When 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.843844```845TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.846```847848This limitation can be worked around by passing either:849 - 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))850 - `[nodeStream, 'pipe']` instead of `nodeStream`851852```diffAllow Node.js streams with synchronous methods (#708)ehmickybefore adoption86bdadf
lines 853–854why, one step back853- await execa(..., {stdout: nodeStream});854+ await execa(..., {stdout: [nodeStream, 'pipe']});Document how to pass a Node.js stream to stdin/stdout/stderr (#644)ehmickybefore adoption2500696
line 855why, one step back855```3.3.0ehmickybefore adoptionf1eda9c
lines 856–858why, one step back856857### Retry on error858Improve graceful exit (#714)ehmickybefore adoption5eeaab5
line 859why, one step back859Safely handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:3.3.0ehmickybefore adoptionf1eda9c
lines 860–861why, one step back860861```jsRequire Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 862why, one step back862import pRetry from 'p-retry';3.3.0ehmickybefore adoptionf1eda9c
lines 863–868why, one step back863864const run = async () => {865 const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']);866 return results;867};868Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 869why, one step back869console.log(await pRetry(run, {retries: 5}));3.3.0ehmickybefore adoptionf1eda9c
lines 870–871why, one step back870```871Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 872–886why, one step back872### Cancelling a spawned process873874```js875import {execa} from 'execa';876877const abortController = new AbortController();878const subprocess = execa('node', [], {signal: abortController.signal});879880setTimeout(() => {881 abortController.abort();882}, 1000);883884try {885 await subprocess;886} catch (error) {Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 887why, one step back887 console.log(error.isTerminated); // trueImprove documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 888–891why, one step back888 console.log(error.isCanceled); // true889}890```8913.3.0ehmickybefore adoptionf1eda9c
lines 892–893why, one step back892### Execute the current package's binary893Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
lines 894–895why, one step back894Execa 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.8953.3.0ehmickybefore adoptionf1eda9c
line 896why, one step back896```jsImprove documentation of the usage section (#541)ehmickybefore adoption5320fef
line 897why, one step back897import {getBinPath} from 'get-bin-path';3.3.0ehmickybefore adoptionf1eda9c
line 898why, one step back898Improve documentation of the usage section (#541)ehmickybefore adoption5320fef
lines 899–900why, one step back899const binPath = await getBinPath();900await execa(binPath);3.3.0ehmickybefore adoptionf1eda9c
lines 901–902why, one step back901```902Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
line 903why, one step back903### Ensuring `all` output is interleaved3.3.0ehmickybefore adoptionf1eda9c
line 904why, one step back904Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
lines 905–935why, one step back905The `all` [stream](#all) and [string/`Uint8Array`](#all-1) properties are guaranteed to interleave [`stdout`](#stdout) and [`stderr`](#stderr).906907However, for performance reasons, the child process might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This prevents proper interleaving.908909For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.910911```js912import {execa} from 'execa';913914const {all} = await execa('node', ['example.js'], {all: true});915console.log(all);916```917918```js919// example.js920console.log('1'); // writes to stdout921console.error('2'); // writes to stderr922console.log('3'); // writes to stdout923```924925This can be worked around by using `setTimeout()`.926927```js928import {setTimeout} from 'timers/promises';929930console.log('1');931console.error('2');932await setTimeout(0);933console.log('3');934```9353.3.0ehmickybefore adoptionf1eda9c
lines 936–937why, one step back936## Related937Document workaround for proper `all` interleaving (#640)ehmickybefore adoption21d69c0
lines 938–939why, one step back938- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa939- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version3.3.0ehmickybefore adoptionf1eda9c
lines 940–944why, one step back940941## Maintainers942943- [Sindre Sorhus](https://github.com/sindresorhus)944- [@ehmicky](https://github.com/ehmicky)