Move API reference to its own page (#996)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent ceb1069 · Browse files · 21 files·+1151 added−1137 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+1151 added−1137 removed
- other:+1151 added−1137 removed
Provenance
- Commit
7cde496- Tree
b64d849- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
ceb1069
21 files changed+1151 added−1137 removed
added:docs/api.md+1029 added
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>6+7+# 📔 API reference8+9+This lists all available [methods](#methods) and their [options](#options). This also describes the properties of the [subprocess](#subprocess), [result](#result) and [error](#execaerror) they return.10+11+## Methods12+13+### execa(file, arguments?, options?)14+15+`file`: `string | URL`\16+`arguments`: `string[]`\17+`options`: [`Options`](#options)\18+_Returns_: [`Subprocess`](#subprocess)19+20+Executes a command using `file ...arguments`.21+22+More info on the [syntax](execution.md#array-syntax) and [escaping](escaping.md#array-syntax).23+24+### execa\`command\`25+### execa(options)\`command\`26+27+`command`: `string`\28+`options`: [`Options`](#options)\29+_Returns_: [`Subprocess`](#subprocess)30+31+Executes a command. `command` is a [template string](execution.md#template-string-syntax) that includes both the `file` and its `arguments`.32+33+More info on the [syntax](execution.md#template-string-syntax) and [escaping](escaping.md#template-string-syntax).34+35+### execa(options)36+37+`options`: [`Options`](#options)\38+_Returns_: [`execa`](#execafile-arguments-options)39+40+Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.41+42+[More info.](execution.md#globalshared-options)43+44+### execaSync(file, arguments?, options?)45+### execaSync\`command\`46+47+Same as [`execa()`](#execafile-arguments-options) but synchronous.48+49+Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.50+51+[More info.](execution.md#synchronous-execution)52+53+### $(file, arguments?, options?)54+55+`file`: `string | URL`\56+`arguments`: `string[]`\57+`options`: [`Options`](#options)\58+_Returns_: [`Subprocess`](#subprocess)59+60+Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](scripts.md#script-files).61+62+Just like `execa()`, this can use the [template string syntax](execution.md#template-string-syntax) or [bind options](execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.63+64+This is the preferred method when executing multiple commands in a script file.65+66+[More info.](scripts.md)67+68+### execaNode(scriptPath, arguments?, options?)69+70+`scriptPath`: `string | URL`\71+`arguments`: `string[]`\72+`options`: [`Options`](#options)\73+_Returns_: [`Subprocess`](#subprocess)74+75+Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.76+Executes a Node.js file using `node scriptPath ...arguments`.77+78+Just like `execa()`, this can use the [template string syntax](execution.md#template-string-syntax) or [bind options](execution.md#globalshared-options).79+80+This is the preferred method when executing Node.js files.81+82+[More info.](node.md)83+84+### execaCommand(command, options?)85+86+`command`: `string`\87+`options`: [`Options`](#options)\88+_Returns_: [`Subprocess`](#subprocess)89+90+Executes a command. `command` is a string that includes both the `file` and its `arguments`.91+92+This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.93+94+Just like `execa()`, this can [bind options](execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.95+96+[More info.](escaping.md#user-defined-input)97+98+## Subprocess99+100+The return value of all [asynchronous methods](#methods) is both:101+- a `Promise` resolving or rejecting with a subprocess [`result`](#result).102+- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.103+104+[More info.](execution.md#subprocess)105+106+### subprocess\[Symbol.asyncIterator\]()107+108+_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)109+110+Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.111+112+[More info.](lines.md#progressive-splitting)113+114+### subprocess.iterable(readableOptions?)115+116+`readableOptions`: [`ReadableOptions`](#readableoptions)\117+_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)118+119+Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.120+121+[More info.](lines.md#progressive-splitting)122+123+### subprocess.pipe(file, arguments?, options?)124+125+`file`: `string | URL`\126+`arguments`: `string[]`\127+`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\128+_Returns_: [`Promise<Result>`](#result)129+130+[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' [`stdout`](#subprocessstdout) to a second Execa subprocess' [`stdin`](#subprocessstdin). This resolves with that second subprocess' [result](#result). If either subprocess is rejected, this is rejected with that subprocess' [error](#execaerror) instead.131+132+This 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.133+134+[More info.](pipe.md#array-syntax)135+136+### subprocess.pipe\`command\`137+### subprocess.pipe(options)\`command\`138+139+`command`: `string`\140+`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\141+_Returns_: [`Promise<Result>`](#result)142+143+Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).144+145+[More info.](pipe.md#template-string-syntax)146+147+### subprocess.pipe(secondSubprocess, pipeOptions?)148+149+`secondSubprocess`: [`execa()` return value](#subprocess)\150+`pipeOptions`: [`PipeOptions`](#pipeoptions)\151+_Returns_: [`Promise<Result>`](#result)152+153+Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#subprocess) of another [`execa()`](#execafile-arguments-options) call instead.154+155+[More info.](pipe.md#advanced-syntax)156+157+#### pipeOptions158+159+Type: `object`160+161+#### pipeOptions.from162+163+Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\164+Default: `"stdout"`165+166+Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.167+168+`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.169+170+[More info.](pipe.md#source-file-descriptor)171+172+#### pipeOptions.to173+174+Type: `"stdin" | "fd3" | "fd4" | ...`\175+Default: `"stdin"`176+177+Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.178+179+[More info.](pipe.md#destination-file-descriptor)180+181+#### pipeOptions.unpipeSignal182+183+Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)184+185+Unpipe the subprocess when the signal aborts.186+187+[More info.](pipe.md#unpipe)188+189+### subprocess.kill(signal, error?)190+### subprocess.kill(error?)191+192+`signal`: `string | number`\193+`error`: `Error`\194+_Returns_: `boolean`195+196+Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#optionskillsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#resultisterminated) the subprocess.197+198+This returns `false` when the signal could not be sent, for example when the subprocess has already exited.199+200+When an error is passed as argument, it is set to the subprocess' [`error.cause`](#errorcause). The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).201+202+[More info.](termination.md)203+204+### subprocess.pid205+206+_Type_: `number | undefined`207+208+Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).209+210+This is `undefined` if the subprocess failed to spawn.211+212+[More info.](termination.md#inter-process-termination)213+214+### subprocess.send(message)215+216+`message`: `unknown`\217+_Returns_: `boolean`218+219+Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.220+The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).221+222+This returns `true` on success.223+224+This requires the [`ipc`](#optionsipc) option to be `true`.225+226+[More info.](ipc.md#exchanging-messages)227+228+### subprocess.on('message', (message) => void)229+230+`message`: `unknown`231+232+Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.233+The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).234+235+This requires the [`ipc`](#optionsipc) option to be `true`.236+237+[More info.](ipc.md#exchanging-messages)238+239+### subprocess.stdin240+241+Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)242+243+The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.244+245+This is `null` if the [`stdin`](#optionsstdin) option is set to [`'inherit'`](input.md#terminal-input), [`'ignore'`](input.md#ignore-input), [`Readable`](streams.md#input) or [`integer`](input.md#terminal-input).246+247+[More info.](streams.md#manual-streaming)248+249+### subprocess.stdout250+251+Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)252+253+The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.254+255+This is `null` if the [`stdout`](#optionsstdout) option is set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.256+257+[More info.](streams.md#manual-streaming)258+259+### subprocess.stderr260+261+Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)262+263+The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.264+265+This is `null` if the [`stderr`](#optionsstdout) option is set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.266+267+[More info.](streams.md#manual-streaming)268+269+### subprocess.all270+271+Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)272+273+Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).274+275+This requires the [`all`](#optionsall) option to be `true`.276+277+This is `undefined` if [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.278+279+More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).280+281+### subprocess.stdio282+283+Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)284+285+The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.286+287+Each array item is `null` if the corresponding [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option is set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Stream`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.288+289+[More info.](streams.md#manual-streaming)290+291+### subprocess.readable(readableOptions?)292+293+`readableOptions`: [`ReadableOptions`](#readableoptions)\294+_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream295+296+Converts the subprocess to a readable stream.297+298+[More info.](streams.md#converting-a-subprocess-to-a-stream)299+300+#### readableOptions301+302+Type: `object`303+304+#### readableOptions.from305+306+Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\307+Default: `"stdout"`308+309+Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.310+311+`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.312+313+[More info.](streams.md#different-file-descriptor)314+315+#### readableOptions.binary316+317+Type: `boolean`\318+Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)319+320+If `false`, iterates over lines. Each line is a string.321+322+If `true`, iterates over arbitrary chunks of data. Each line is an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) (with [`subprocess.iterable()`](#subprocessiterablereadableoptions)) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)).323+324+This is always `true` when the [`encoding`](#optionsencoding) option is binary.325+326+More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).327+328+#### readableOptions.preserveNewlines329+330+Type: `boolean`\331+Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)332+333+If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.334+335+[More info.](lines.md#iterable)336+337+### subprocess.writable(writableOptions?)338+339+`writableOptions`: [`WritableOptions`](#writableoptions)\340+_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream341+342+Converts the subprocess to a writable stream.343+344+[More info.](streams.md#converting-a-subprocess-to-a-stream)345+346+#### writableOptions347+348+Type: `object`349+350+#### writableOptions.to351+352+Type: `"stdin" | "fd3" | "fd4" | ...`\353+Default: `"stdin"`354+355+Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.356+357+[More info.](streams.md#different-file-descriptor)358+359+### subprocess.duplex(duplexOptions?)360+361+`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\362+_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream363+364+Converts the subprocess to a duplex stream.365+366+[More info.](streams.md#converting-a-subprocess-to-a-stream)367+368+## Result369+370+Type: `object`371+372+[Result](execution.md#result) of a subprocess execution.373+374+When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.375+376+### result.stdout377+378+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`379+380+The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).381+382+This is `undefined` if the [`stdout`](#optionsstdout) option is set to only [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.383+384+This is an array if the [`lines`](#optionslines) option is `true`, or if the `stdout` option is a [transform in object mode](transform.md#object-mode).385+386+[More info.](output.md#stdout-and-stderr)387+388+### result.stderr389+390+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`391+392+The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).393+394+This is `undefined` if the [`stderr`](#optionsstderr) option is set to only [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.395+396+This is an array if the [`lines`](#optionslines) option is `true`, or if the `stderr` option is a [transform in object mode](transform.md#object-mode).397+398+[More info.](output.md#stdout-and-stderr)399+400+### result.all401+402+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`403+404+The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.405+406+This requires the [`all`](#optionsall) option to be `true`.407+408+This is `undefined` if both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.409+410+This is an array if the [`lines`](#optionslines) option is `true`, or if either the `stdout` or `stderr` option is a [transform in object mode](transform.md#object-mode).411+412+[More info.](output.md#interleaved-output)413+414+### result.stdio415+416+Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`417+418+The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).419+420+Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.421+422+Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).423+424+[More info.](output.md#additional-file-descriptors)425+426+### result.pipedFrom427+428+Type: [`Array<Result | ExecaError>`](#result)429+430+[Results](#result) of the other subprocesses that were piped into this subprocess.431+432+This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.433+434+[More info.](pipe.md#result)435+436+### result.command437+438+Type: `string`439+440+The file and [arguments](input.md#command-arguments) that were run.441+442+[More info.](debugging.md#command)443+444+### result.escapedCommand445+446+Type: `string`447+448+Same as [`command`](#resultcommand) but escaped.449+450+[More info.](debugging.md#command)451+452+### result.cwd453+454+Type: `string`455+456+The [current directory](#optionscwd) in which the command was run.457+458+[More info.](environment.md#current-directory)459+460+### result.durationMs461+462+Type: `number`463+464+Duration of the subprocess, in milliseconds.465+466+[More info.](debugging.md#duration)467+468+### result.failed469+470+Type: `boolean`471+472+Whether the subprocess failed to run.473+474+[More info.](errors.md#subprocess-failure)475+476+### result.timedOut477+478+Type: `boolean`479+480+Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.481+482+[More info.](termination.md#timeout)483+484+### result.isCanceled485+486+Type: `boolean`487+488+Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.489+490+[More info.](termination.md#canceling)491+492+### result.isMaxBuffer493+494+Type: `boolean`495+496+Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.497+498+[More info.](output.md#big-output)499+500+### result.isTerminated501+502+Type: `boolean`503+504+Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:505+- The current process.506+- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).507+508+[More info.](termination.md#signal-name-and-description)509+510+### result.exitCode511+512+Type: `number | undefined`513+514+The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.515+516+This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).517+518+[More info.](errors.md#exit-code)519+520+### result.signal521+522+Type: `string | undefined`523+524+The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:525+- The current process.526+- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).527+528+If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.529+530+[More info.](termination.md#signal-name-and-description)531+532+### result.signalDescription533+534+Type: `string | undefined`535+536+A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.537+538+If 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.539+540+[More info.](termination.md#signal-name-and-description)541+542+## ExecaError543+## ExecaSyncError544+545+Type: `Error`546+547+Exception thrown when the subprocess [fails](errors.md#subprocess-failure).548+549+This has the same shape as [successful results](#result), with the following additional properties.550+551+[More info.](errors.md)552+553+### error.message554+555+Type: `string`556+557+Error message when the subprocess [failed](errors.md#subprocess-failure) to run.558+559+[More info.](errors.md#error-message)560+561+### error.shortMessage562+563+Type: `string`564+565+This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).566+567+[More info.](errors.md#error-message)568+569+### error.originalMessage570+571+Type: `string | undefined`572+573+Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.574+575+[More info.](errors.md#error-message)576+577+### error.cause578+579+Type: `unknown | undefined`580+581+Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).582+583+This is usually an `Error` instance.584+585+[More info.](termination.md#error-message-and-stack-trace)586+587+### error.code588+589+Type: `string | undefined`590+591+Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.592+593+## Options594+595+Type: `object`596+597+This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).598+599+The following options [can specify different values](output.md#stdoutstderr-specific-options) for [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr): [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`buffer`](#optionsbuffer), [`maxBuffer`](#optionsmaxbuffer).600+601+### options.preferLocal602+603+Type: `boolean`\604+Default: `true` with [`$`](#file-arguments-options), `false` otherwise605+606+Prefer locally installed binaries when looking for a binary to execute.607+608+[More info.](environment.md#local-binaries)609+610+### options.localDir611+612+Type: `string | URL`\613+Default: [`cwd`](#optionscwd) option614+615+Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.616+617+[More info.](environment.md#local-binaries)618+619+### options.node620+621+Type: `boolean`\622+Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise623+624+If `true`, runs with Node.js. The first argument must be a Node.js file.625+626+[More info.](node.md)627+628+### options.nodeOptions629+630+Type: `string[]`\631+Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)632+633+List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).634+635+Requires the [`node`](#optionsnode) option to be `true`.636+637+[More info.](node.md#nodejs-cli-flags)638+639+### options.nodePath640+641+Type: `string | URL`\642+Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)643+644+Path to the Node.js executable.645+646+Requires the [`node`](#optionsnode) option to be `true`.647+648+[More info.](node.md#nodejs-version)649+650+### options.shell651+652+Type: `boolean | string | URL`\653+Default: `false`654+655+If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).656+657+Uses [`/bin/sh`](https://en.wikipedia.org/wiki/Unix_shell) on UNIX and [`cmd.exe`](https://en.wikipedia.org/wiki/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.658+659+We [recommend against](shell.md#avoiding-shells) using this option.660+661+[More info.](shell.md)662+663+### options.cwd664+665+Type: `string | URL`\666+Default: `process.cwd()`667+668+Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.669+670+This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.671+672+[More info.](environment.md#current-directory)673+674+### options.env675+676+Type: `object`\677+Default: [`process.env`](https://nodejs.org/api/process.html#processenv)678+679+[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).680+681+Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).682+683+[More info.](input.md#environment-variables)684+685+### options.extendEnv686+687+Type: `boolean`\688+Default: `true`689+690+If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).691+If `false`, only the `env` option is used, not `process.env`.692+693+[More info.](input.md#environment-variables)694+695+### options.input696+697+Type: `string | Uint8Array | stream.Readable`698+699+Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).700+701+See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.702+703+[More info.](input.md#string-input)704+705+### options.inputFile706+707+Type: `string | URL`708+709+Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).710+711+See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.712+713+[More info.](input.md#file-input)714+715+### options.stdin716+717+Type: `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)\718+Default: `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise719+720+How to setup the subprocess' [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](streams.md#manual-streaming), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore`](input.md#ignore-input), [`'inherit'`](input.md#terminal-input), a [file descriptor integer](input.md#terminal-input), a [Node.js `Readable` stream](streams.md#input), a web [`ReadableStream`](streams.md#web-streams), a [`{ file: 'path' }` object](input.md#file-input), a [file URL](input.md#file-input), an [`Iterable`](streams.md#iterables-as-input) (including an [array of strings](input.md#string-input)), an [`AsyncIterable`](streams.md#iterables-as-input), an [`Uint8Array`](binary.md#binary-input), a [generator function](transform.md), a [`Duplex`](transform.md#duplextransform-streams) or a web [`TransformStream`](transform.md#duplextransform-streams).721+722+This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.723+724+More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).725+726+### options.stdout727+728+Type: `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)\729+Default: `pipe`730+731+How to setup the subprocess' [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](output.md#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore`](output.md#ignore-output), [`'inherit'`](output.md#terminal-output), a [file descriptor integer](output.md#terminal-output), a [Node.js `Writable` stream](streams.md#output), a web [`WritableStream`](streams.md#web-streams), a [`{ file: 'path' }` object](output.md#file-output), a [file URL](output.md#file-output), a [generator function](transform.md), a [`Duplex`](transform.md#duplextransform-streams) or a web [`TransformStream`](transform.md#duplextransform-streams).732+733+This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.734+735+More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).736+737+### options.stderr738+739+Type: `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)\740+Default: `pipe`741+742+How to setup the subprocess' [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](output.md#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore`](output.md#ignore-output), [`'inherit'`](output.md#terminal-output), a [file descriptor integer](output.md#terminal-output), a [Node.js `Writable` stream](streams.md#output), a web [`WritableStream`](streams.md#web-streams), a [`{ file: 'path' }` object](output.md#file-output), a [file URL](output.md#file-output), a [generator function](transform.md), a [`Duplex`](transform.md#duplextransform-streams) or a web [`TransformStream`](transform.md#duplextransform-streams).743+744+This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.745+746+More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).747+748+### options.stdio749+750+Type: `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)\751+Default: `pipe`752+753+Like the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options but for all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.754+755+A single string can be used [as a shortcut](output.md#shortcut).756+757+The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).758+759+More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).760+761+### options.all762+763+Type: `boolean`\764+Default: `false`765+766+Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.767+768+[More info.](output.md#interleaved-output)769+770+### options.encoding771+772+Type: `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\773+Default: `'utf8'`774+775+If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).776+777+If it outputs binary data instead, this should be either:778+- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).779+- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'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.780+781+The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).782+783+[More info.](binary.md)784+785+### options.lines786+787+Type: `boolean`\788+Default: `false`789+790+Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.791+792+This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).793+794+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).795+796+[More info.](lines.md#simple-splitting)797+798+### options.stripFinalNewline799+800+Type: `boolean`\801+Default: `true`802+803+Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.804+805+If the [`lines`](#optionslines) option is true, this applies to each output line instead.806+807+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).808+809+[More info.](lines.md#newlines)810+811+### options.maxBuffer812+813+Type: `number`\814+Default: `100_000_000`815+816+Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).817+818+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).819+820+[More info.](output.md#big-output)821+822+### options.buffer823+824+Type: `boolean`\825+Default: `true`826+827+When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.828+829+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).830+831+[More info.](output.md#low-memory)832+833+### options.ipc834+835+Type: `boolean`\836+Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise837+838+Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).839+840+[More info.](ipc.md)841+842+### options.serialization843+844+Type: `'json' | 'advanced'`\845+Default: `'advanced'`846+847+Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.848+849+[More info.](ipc.md#message-type)850+851+### options.verbose852+853+Type: `'none' | 'short' | 'full'`\854+Default: `'none'`855+856+If `verbose` is `'short'`, prints the command on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)): its file, arguments, duration and (if it failed) error message.857+858+If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.859+860+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).861+862+[More info.](debugging.md#verbose-mode)863+864+### options.reject865+866+Type: `boolean`\867+Default: `true`868+869+Setting this to `false` resolves the [result's promise](#subprocess) with the [error](#execaerror) instead of rejecting it.870+871+[More info.](errors.md#preventing-exceptions)872+873+### options.timeout874+875+Type: `number`\876+Default: `0`877+878+If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.879+880+On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.881+882+[More info.](termination.md#timeout)883+884+### options.cancelSignal885+886+Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)887+888+You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).889+890+When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.891+892+[More info.](termination.md#canceling)893+894+### options.forceKillAfterDelay895+896+Type: `number | false`\897+Default: `5000`898+899+If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).900+901+[More info.](termination.md#forceful-termination)902+903+### options.killSignal904+905+Type: `string | number`\906+Default: `'SIGTERM'`907+908+Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.909+910+This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).911+912+[More info.](termination.md#default-signal)913+914+### options.detached915+916+Type: `boolean`\917+Default: `false`918+919+Run the subprocess independently from the current process.920+921+[More info.](environment.md#background-subprocess)922+923+### options.cleanup924+925+Type: `boolean`\926+Default: `true`927+928+Kill the subprocess when the current process exits.929+930+[More info.](termination.md#current-process-exit)931+932+### options.uid933+934+Type: `number`\935+Default: current user identifier936+937+Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.938+939+[More info.](windows.md#uid-and-gid)940+941+### options.gid942+943+Type: `number`\944+Default: current group identifier945+946+Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.947+948+[More info.](windows.md#uid-and-gid)949+950+### options.argv0951+952+Type: `string`\953+Default: file being executed954+955+Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.956+957+### options.windowsHide958+959+Type: `boolean`\960+Default: `true`961+962+On Windows, do not create a new console window.963+964+[More info.](windows.md#console-window)965+966+### options.windowsVerbatimArguments967+968+Type: `boolean`\969+Default: `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise970+971+If `false`, escapes the command arguments on Windows.972+973+[More info.](windows.md#cmdexe-escaping)974+975+## Transform options976+977+A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.978+979+A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.980+981+[More info.](transform.md)982+983+### transformOptions.transform984+985+Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`986+987+Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.988+989+More info [here](transform.md#summary) and [there](transform.md#sharing-state).990+991+### transformOptions.final992+993+Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`994+995+Create additional lines after the last one.996+997+[More info.](transform.md#finalizing)998+999+### transformOptions.binary1000+1001+Type: `boolean`\1002+Default: `false`1003+1004+If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.1005+1006+[More info.](binary.md#transforms)1007+1008+### transformOptions.preserveNewlines1009+1010+Type: `boolean`\1011+Default: `false`1012+1013+If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.1014+1015+[More info.](lines.md#transforms)1016+1017+### transformOptions.objectMode1018+1019+Type: `boolean`\1020+Default: `false`1021+1022+If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.1023+1024+[More info.](transform.md#object-mode)1025+1026+<hr>1027+1028+[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1029+[**Top**: Table of contents](../readme.md#documentation)modified:docs/bash.md+1 added
858 unmodified lines859 [More info.](termination.md#inter-process-termination)860 861 <hr>862 863+[**Next**: 📔 API reference](api.md)\864 [**Previous**: 📎 Windows](windows.md)\865 [**Top**: Table of contents](../readme.md#documentation)modified:docs/binary.md+6 added-6 removed
6 unmodified lines789101111121314154 unmodified lines20212223242425262728293031323333343536373839404142424344454647484950515252535455565 unmodified lines626364656666676869709 unmodified lines6 unmodified lines# 🤖 Binary data
## Binary input
There are multiple ways to pass binary input using the [`stdin`](../readme.md#optionsstdin), [`input`](../readme.md#optionsinput) or [`inputFile`](../readme.md#optionsinputfile) options: `Uint8Array`s, [files](input.md#file-input), [streams](streams.md) or [other subprocesses](pipe.md).There are multiple ways to pass binary input using the [`stdin`](api.md#optionsstdin), [`input`](api.md#optionsinput) or [`inputFile`](api.md#optionsinputfile) options: `Uint8Array`s, [files](input.md#file-input), [streams](streams.md) or [other subprocesses](pipe.md).
This is required if the subprocess input includes [null bytes](https://en.wikipedia.org/wiki/Null_character).
```js4 unmodified lines```
## Binary output
By default, the subprocess [output](../readme.md#resultstdout) is a [UTF8](https://en.wikipedia.org/wiki/UTF-8) string. If it is binary, the [`encoding`](../readme.md#optionsencoding) option should be set to `'buffer'` instead. The output will be an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).By default, the subprocess [output](api.md#resultstdout) is a [UTF8](https://en.wikipedia.org/wiki/UTF-8) string. If it is binary, the [`encoding`](api.md#optionsencoding) option should be set to `'buffer'` instead. The output will be an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
```jsconst {stdout} = await execa({encoding: 'buffer'})`zip -r - input.txt`;console.log(stdout.byteLength);```
## Encoding
When the output is binary, the [`encoding`](../readme.md#optionsencoding) option can also be set to [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64) or [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications). The output will be a string then.When the output is binary, the [`encoding`](api.md#optionsencoding) option can also be set to [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64) or [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications). The output will be a string then.
```jsconst {stdout} = await execa({encoding: 'hex'})`zip -r - input.txt`;console.log(stdout); // Hexadecimal string```
## Iterable
By default, the subprocess [iterates](lines.md#progressive-splitting) over line strings. However, if the [`encoding`](../readme.md#optionsencoding) subprocess option is binary, or if the [`binary`](../readme.md#readableoptionsbinary) iterable option is `true`, it iterates over arbitrary chunks of [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) data instead.By default, the subprocess [iterates](lines.md#progressive-splitting) over line strings. However, if the [`encoding`](api.md#optionsencoding) subprocess option is binary, or if the [`binary`](api.md#readableoptionsbinary) iterable option is `true`, it iterates over arbitrary chunks of [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) data instead.
```jsfor await (const data of execa({encoding: 'buffer'})`zip -r - input.txt`) { /* ... */}```
## Transforms
The same applies to transforms. When the [`encoding`](../readme.md#optionsencoding) subprocess option is binary, or when the [`binary`](../readme.md#transformoptionsbinary) transform option is `true`, it iterates over arbitrary chunks of [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) data instead.The same applies to transforms. When the [`encoding`](api.md#optionsencoding) subprocess option is binary, or when the [`binary`](api.md#transformoptionsbinary) transform option is `true`, it iterates over arbitrary chunks of [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) data instead.
However, transforms can always `yield` either a `string` or an `Uint8Array`, regardless of whether the output is binary or not.
```js5 unmodified lines```
## Streams
[Streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions) and [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions) are binary by default, which means they iterate over arbitrary [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) chunks. However, if the [`binary`](../readme.md#readableoptionsbinary) option is `false`, they iterate over line strings instead, and the stream is [in object mode](https://nodejs.org/api/stream.html#object-mode).[Streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](api.md#subprocessreadablereadableoptions) and [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions) are binary by default, which means they iterate over arbitrary [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) chunks. However, if the [`binary`](api.md#readableoptionsbinary) option is `false`, they iterate over line strings instead, and the stream is [in object mode](https://nodejs.org/api/stream.html#object-mode).
```jsconst readable = execa`npm run build`.readable({binary: false});readable.on('data', lineString => {9 unmodified linesmodified:docs/debugging.md+8 added-8 removed
6 unmodified lines7891011111213131415151617181921 unmodified lines414243444545464748496 unmodified lines56575859606061626363646565666768698 unmodified lines7879808182828384858619 unmodified lines6 unmodified lines# 🐛 Debugging
## Command
[`error.command`](../readme.md#resultcommand) contains the file and [arguments](input.md#command-arguments) that were run. It is intended for logging or debugging.[`error.command`](api.md#resultcommand) contains the file and [arguments](input.md#command-arguments) that were run. It is intended for logging or debugging.
[`error.escapedCommand`](../readme.md#resultescapedcommand) is the same, except control characters are escaped. This makes it safe to either print or copy and paste in a terminal, for debugging purposes.[`error.escapedCommand`](api.md#resultescapedcommand) is the same, except control characters are escaped. This makes it safe to either print or copy and paste in a terminal, for debugging purposes.
Since the escaping is fairly basic, neither `error.command` nor `error.escapedCommand` should be executed directly, including using [`execa()`](../readme.md#execafile-arguments-options) or [`execaCommand()`](../readme.md#execacommandcommand-options).Since the escaping is fairly basic, neither `error.command` nor `error.escapedCommand` should be executed directly, including using [`execa()`](api.md#execafile-arguments-options) or [`execaCommand()`](api.md#execacommandcommand-options).
```jsimport {execa} from 'execa';
21 unmodified lines## Verbose mode
### Short mode
When the [`verbose`](../readme.md#optionsverbose) option is `'short'`, the [command](#command), [duration](#duration) and [error messages](errors.md#error-message) are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).When the [`verbose`](api.md#optionsverbose) option is `'short'`, the [command](#command), [duration](#duration) and [error messages](errors.md#error-message) are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
```js// build.jsawait execa({verbose: 'short'})`npm run build`;6 unmodified lines```
### Full mode
When the [`verbose`](../readme.md#optionsverbose) option is `'full'`, the subprocess' [`stdout` and `stderr`](output.md) are also logged. Both are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).When the [`verbose`](api.md#optionsverbose) option is `'full'`, the subprocess' [`stdout` and `stderr`](output.md) are also logged. Both are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
The output is not logged if either:- The [`stdout`](../readme.md#optionsstdout)/[`stderr`](../readme.md#optionsstderr) option is [`'ignore'`](output.md#ignore-output) or [`'inherit'`](output.md#terminal-output).- The [`stdout`](api.md#optionsstdout)/[`stderr`](api.md#optionsstderr) option is [`'ignore'`](output.md#ignore-output) or [`'inherit'`](output.md#terminal-output).- The `stdout`/`stderr` is redirected to [a stream](streams.md#output), [a file](output.md#file-output), [a file descriptor](output.md#terminal-output), or [another subprocess](pipe.md).- The [`encoding`](../readme.md#optionsencoding) option is [binary](binary.md#binary-output).- The [`encoding`](api.md#optionsencoding) option is [binary](binary.md#binary-output).
```js// build.jsawait execa({verbose: 'full'})`npm run build`;8 unmodified lines```
### Global mode
When the `NODE_DEBUG=execa` [environment variable](https://en.wikipedia.org/wiki/Environment_variable) is set, the [`verbose`](../readme.md#optionsverbose) option defaults to `'full'` for all commands.When the `NODE_DEBUG=execa` [environment variable](https://en.wikipedia.org/wiki/Environment_variable) is set, the [`verbose`](api.md#optionsverbose) option defaults to `'full'` for all commands.
```js// build.js
19 unmodified linesmodified:docs/environment.md+5 added-5 removed
6 unmodified lines7 # 🌐 Environment8 9 ## Current directory10 11-The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](../readme.md#optionscwd) option.11+The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](api.md#optionscwd) option.12 13 ```js14 import {execa} from 'execa';15 16 await execa({cwd: '/path/to/cwd'})`npm run build`;17 ```18 19-And be retrieved with the [`result.cwd`](../readme.md#resultcwd) property.19+And be retrieved with the [`result.cwd`](api.md#resultcwd) property.20 21 ```js22 const {cwd} = await execa`npm run build`;23 ```9 unmodified lines33 ```js34 await execa('./node_modules/.bin/eslint');35 ```36 37-The [`preferLocal`](../readme.md#optionspreferlocal) option can be used to execute those local binaries.37+The [`preferLocal`](api.md#optionspreferlocal) option can be used to execute those local binaries.38 39 ```js40 await execa('eslint', {preferLocal: true});41 ```42 43-Those are searched in the current or any parent directory. The [`localDir`](../readme.md#optionslocaldir) option can select a different directory.43+Those are searched in the current or any parent directory. The [`localDir`](api.md#optionslocaldir) option can select a different directory.44 45 ```js46 await execa('eslint', {preferLocal: true, localDir: '/path/to/dir'});47 ```11 unmodified lines59 ```60 61 ## Background subprocess62 63-When the [`detached`](../readme.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.63+When the [`detached`](api.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.64 65 Specific behavior depends on the platform. [More info.](https://nodejs.org/api/child_process.html#child_process_options_detached)66 67 ```js8 unmodified linesmodified:docs/errors.md+11 added-11 removed
6 unmodified lines7 # ❌ Errors8 9 ## Subprocess failure10 11-When the subprocess fails, the promise returned by [`execa()`](../readme.md#execafile-arguments-options) is rejected with an [`ExecaError`](../readme.md#execaerror) instance. The `error` has the same shape as successful [results](../readme.md#result), with a few additional [error-specific fields](../readme.md#execaerror). [`error.failed`](../readme.md#resultfailed) is always `true`.11+When the subprocess fails, the promise returned by [`execa()`](api.md#execafile-arguments-options) is rejected with an [`ExecaError`](api.md#execaerror) instance. The `error` has the same shape as successful [results](api.md#result), with a few additional [error-specific fields](api.md#execaerror). [`error.failed`](api.md#resultfailed) is always `true`.12 13 ```js14 import {execa, ExecaError} from 'execa';15 8 unmodified lines24 ```25 26 ## Preventing exceptions27 28-When the [`reject`](../readme.md#optionsreject) option is `false`, the `error` is returned instead.28+When the [`reject`](api.md#optionsreject) option is `false`, the `error` is returned instead.29 30 ```js31 const resultOrError = await execa`npm run build`;32 if (resultOrError.failed) {2 unmodified lines35 ```36 37 ## Exit code38 39-The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](../readme.md#resultexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).39+The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](api.md#resultexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).40 41 ```js42 try {43 await execa`npm run build`;5 unmodified lines49 50 ## Failure reason51 52 The subprocess can fail for other reasons. Some of them can be detected using a specific boolean property:53-- [`error.timedOut`](../readme.md#resulttimedout): [`timeout`](termination.md#timeout) option.54-- [`error.isCanceled`](../readme.md#resultiscanceled): [`cancelSignal`](termination.md#canceling) option.55-- [`error.isMaxBuffer`](../readme.md#resultismaxbuffer): [`maxBuffer`](output.md#big-output) option.56-- [`error.isTerminated`](../readme.md#resultisterminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.53+- [`error.timedOut`](api.md#resulttimedout): [`timeout`](termination.md#timeout) option.54+- [`error.isCanceled`](api.md#resultiscanceled): [`cancelSignal`](termination.md#canceling) option.55+- [`error.isMaxBuffer`](api.md#resultismaxbuffer): [`maxBuffer`](output.md#big-output) option.56+- [`error.isTerminated`](api.md#resultisterminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.57 58 Otherwise, the subprocess failed because either:59 - An exception was thrown in a [stream](streams.md) or [transform](transform.md).60 - The command's executable file was not found.61-- An invalid [option](../readme.md#options) was passed.61+- An invalid [option](api.md#options) was passed.62 - There was not enough memory or too many subprocesses.63 64 ```js65 try {8 unmodified lines74 ```75 76 ## Error message77 78-For better [debugging](debugging.md), [`error.message`](../readme.md#errormessage) includes both:78+For better [debugging](debugging.md), [`error.message`](api.md#errormessage) includes both:79 - The command and the [reason it failed](#failure-reason).80 - Its [`stdout`, `stderr`](output.md#stdout-and-stderr) and [other file descriptors'](output.md#additional-file-descriptors) output, separated with newlines and not [interleaved](output.md#interleaved-output).81 82-[`error.shortMessage`](../readme.md#errorshortmessage) is the same but without `stdout`/`stderr`.82+[`error.shortMessage`](api.md#errorshortmessage) is the same but without `stdout`/`stderr`.83 84-[`error.originalMessage`](../readme.md#errororiginalmessage) is the same but also without the command. This exists only in specific instances, such as when calling [`subprocess.kill(error)`](termination.md#error-message-and-stack-trace), using the [`cancelSignal`](termination.md#canceling) option, passing an invalid command or [option](../readme.md#options), or throwing an exception in a [stream](streams.md) or [transform](transform.md).84+[`error.originalMessage`](api.md#errororiginalmessage) is the same but also without the command. This exists only in specific instances, such as when calling [`subprocess.kill(error)`](termination.md#error-message-and-stack-trace), using the [`cancelSignal`](termination.md#canceling) option, passing an invalid command or [option](api.md#options), or throwing an exception in a [stream](streams.md) or [transform](transform.md).85 86 ```js87 try {88 await execa`npm run build`;33 unmodified linesmodified:docs/escaping.md+2 added-2 removed
34 unmodified lines35 await execa(command, commandArguments);36 await execa`${command} ${commandArguments}`;37 ```38 39-However, [`execaCommand()`](../readme.md#execacommandcommand-options) must be used instead if:39+However, [`execaCommand()`](api.md#execacommandcommand-options) must be used instead if:40 - _Both_ the file and its arguments are user-defined41 - _And_ those are supplied as a single string42 43 This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.11 unmodified lines55 ```56 57 ## Shells58 59-[Shells](shell.md) ([Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), [cmd.exe](https://en.wikipedia.org/wiki/Cmd.exe), etc.) are not used unless the [`shell`](../readme.md#optionsshell) option is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.59+[Shells](shell.md) ([Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), [cmd.exe](https://en.wikipedia.org/wiki/Cmd.exe), etc.) are not used unless the [`shell`](api.md#optionsshell) option is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.60 61 If you do set the `shell` option, arguments will not be automatically escaped anymore. Instead, they will be concatenated as a single string using spaces as delimiters.62 63 ```js24 unmodified linesmodified:docs/execution.md+13 added-13 removed
14 unmodified lines15 ```16 17 ## Template string syntax18 19-All [available methods](../readme.md#methods) can use either the [array syntax](#array-syntax) or the template string syntax, which are equivalent.19+All [available methods](api.md#methods) can use either the [array syntax](#array-syntax) or the template string syntax, which are equivalent.20 21 ```js22 await execa`npm run build`;23 ```43 unmodified lines67 ```68 69 ## Options70 71-[Options](../readme.md#options) can be passed to influence the execution's behavior.71+[Options](api.md#options) can be passed to influence the execution's behavior.72 73 ### Array syntax74 75 ```js18 unmodified lines94 ## Return value95 96 ### Subprocess97 98-The subprocess is returned as soon as it is spawned. It is a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with [additional methods and properties](../readme.md#subprocess).98+The subprocess is returned as soon as it is spawned. It is a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with [additional methods and properties](api.md#subprocess).99 100 ```js101 const subprocess = execa`npm run build`;102 console.log(subprocess.pid);103 ```104 105 ### Result106 107-The subprocess is also a `Promise` that resolves with the [`result`](../readme.md#result).107+The subprocess is also a `Promise` that resolves with the [`result`](api.md#result).108 109 ```js110 const {stdout} = await execa`npm run build`;111 ```112 113 ### Synchronous execution114 115-[Every method](../readme.md#methods) can be called synchronously by appending `Sync` to the method's name. The [`result`](../readme.md#result) is returned without needing to `await`. The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.115+[Every method](api.md#methods) can be called synchronously by appending `Sync` to the method's name. The [`result`](api.md#result) is returned without needing to `await`. The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.116 117 ```js118 import {execaSync} from 'execa';119 120 const {stdout} = execaSync`npm run build`;121 ```122 123 Synchronous execution is generally discouraged as it holds the CPU and prevents parallelization. Also, the following features cannot be used:124-- Streams: [`subprocess.stdin`](../readme.md#subprocessstdin), [`subprocess.stdout`](../readme.md#subprocessstdout), [`subprocess.stderr`](../readme.md#subprocessstderr), [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions), [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions).125-- The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and [`stdio`](../readme.md#optionsstdio) options cannot be [`'overlapped'`](../readme.md#optionsstdout), an [async iterable](lines.md#progressive-splitting), an async [transform](transform.md), a [`Duplex`](transform.md#duplextransform-streams), nor a [web stream](streams.md#web-streams). Node.js streams can be passed but only if either they [have a file descriptor](streams.md#file-descriptors), or the [`input`](../readme.md#optionsinput) option is used.126-- Signal termination: [`subprocess.kill()`](../readme.md#subprocesskillerror), [`subprocess.pid`](../readme.md#subprocesspid), [`cleanup`](../readme.md#optionscleanup) option, [`cancelSignal`](../readme.md#optionscancelsignal) option, [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option.127-- Piping multiple subprocesses: [`subprocess.pipe()`](../readme.md#subprocesspipefile-arguments-options).124+- Streams: [`subprocess.stdin`](api.md#subprocessstdin), [`subprocess.stdout`](api.md#subprocessstdout), [`subprocess.stderr`](api.md#subprocessstderr), [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions), [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions).125+- The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and [`stdio`](api.md#optionsstdio) options cannot be [`'overlapped'`](api.md#optionsstdout), an [async iterable](lines.md#progressive-splitting), an async [transform](transform.md), a [`Duplex`](transform.md#duplextransform-streams), nor a [web stream](streams.md#web-streams). Node.js streams can be passed but only if either they [have a file descriptor](streams.md#file-descriptors), or the [`input`](api.md#optionsinput) option is used.126+- Signal termination: [`subprocess.kill()`](api.md#subprocesskillerror), [`subprocess.pid`](api.md#subprocesspid), [`cleanup`](api.md#optionscleanup) option, [`cancelSignal`](api.md#optionscancelsignal) option, [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option.127+- Piping multiple subprocesses: [`subprocess.pipe()`](api.md#subprocesspipefile-arguments-options).128 - [`subprocess.iterable()`](lines.md#progressive-splitting).129-- [`ipc`](../readme.md#optionsipc) and [`serialization`](../readme.md#optionsserialization) options.130-- [`result.all`](../readme.md#resultall) is not interleaved.131-- [`detached`](../readme.md#optionsdetached) option.132-- The [`maxBuffer`](../readme.md#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](../readme.md#optionslines) nor [objects](transform.md#object-mode). Also, it ignores transforms and the [`encoding`](../readme.md#optionsencoding) option.129+- [`ipc`](api.md#optionsipc) and [`serialization`](api.md#optionsserialization) options.130+- [`result.all`](api.md#resultall) is not interleaved.131+- [`detached`](api.md#optionsdetached) option.132+- The [`maxBuffer`](api.md#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](api.md#optionslines) nor [objects](transform.md#object-mode). Also, it ignores transforms and the [`encoding`](api.md#optionsencoding) option.133 134 <hr>135 136 [**Next**: 💬 Escaping/quoting](escaping.md)\1 unmodified linemodified:docs/input.md+3 added-3 removed
50 unmodified lines51 ## String input52 53 Alternatively, input can be provided to [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). Unlike [command arguments](#command-arguments) and [environment variables](#environment-variables) which have [size](https://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument) [limits](https://stackoverflow.com/questions/1078031/what-is-the-maximum-size-of-a-linux-environment-variable-value), `stdin` works when the input is big. Also, the input can be redirected from the [terminal](#terminal-input), a [file](#file-input), another [subprocess](pipe.md) or a [stream](streams.md#manual-streaming). Finally, this is required when the input might contain [null bytes](https://en.wikipedia.org/wiki/Null_character), for example when it might be [binary](binary.md#binary-input).54 55-If the input is already available as a string, it can be passed directly to the [`input`](../readme.md#optionsinput) option.55+If the input is already available as a string, it can be passed directly to the [`input`](api.md#optionsinput) option.56 57 ```js58 await execa({input: 'stdinInput'})`npm run scaffold`;59 ```60 61-The [`stdin`](../readme.md#optionsstdin) option can also be used, although the string must be wrapped in two arrays for [syntax reasons](output.md#multiple-targets).61+The [`stdin`](api.md#optionsstdin) option can also be used, although the string must be wrapped in two arrays for [syntax reasons](output.md#multiple-targets).62 63 ```js64 await execa({stdin: [['stdinInput']]})`npm run scaffold`;65 ```25 unmodified lines91 ```92 93 ## Additional file descriptors94 95-The [`stdio`](../readme.md#optionsstdio) option can be used to pass some input to any [file descriptor](https://en.wikipedia.org/wiki/File_descriptor), as opposed to only [`stdin`](../readme.md#optionsstdin).95+The [`stdio`](api.md#optionsstdio) option can be used to pass some input to any [file descriptor](https://en.wikipedia.org/wiki/File_descriptor), as opposed to only [`stdin`](api.md#optionsstdin).96 97 ```js98 // Pass input to the file descriptor number 399 await execa({9 unmodified linesmodified:docs/ipc.md+3 added-3 removed
6 unmodified lines7 # 📞 Inter-process communication8 9 ## Exchanging messages10 11-When the [`ipc`](../readme.md#optionsipc) option is `true`, the current process and subprocess can exchange messages. This only works if the subprocess is a Node.js file.11+When the [`ipc`](api.md#optionsipc) option is `true`, the current process and subprocess can exchange messages. This only works if the subprocess is a Node.js file.12 13 The `ipc` option defaults to `true` when using [`execaNode()`](node.md#run-nodejs-files) or the [`node`](node.md#run-nodejs-files) option.14 15-The current process sends messages with [`subprocess.send(message)`](../readme.md#subprocesssendmessage) and receives them with [`subprocess.on('message', (message) => {})`](../readme.md#subprocessonmessage-message--void). The subprocess sends messages with [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) and [`process.on('message', (message) => {})`](https://nodejs.org/api/process.html#event-message).15+The current process sends messages with [`subprocess.send(message)`](api.md#subprocesssendmessage) and receives them with [`subprocess.on('message', (message) => {})`](api.md#subprocessonmessage-message--void). The subprocess sends messages with [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) and [`process.on('message', (message) => {})`](https://nodejs.org/api/process.html#event-message).16 17 More info on [sending](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [receiving](https://nodejs.org/api/child_process.html#event-message) messages.18 19 ```js20 unmodified lines40 ## Message type41 42 By default, messages are serialized using [`structuredClone()`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). This supports most types including objects, arrays, `Error`, `Date`, `RegExp`, `Map`, `Set`, `bigint`, `Uint8Array`, and circular references. This throws when passing functions, symbols or promises (including inside an object or array).43 44-To limit messages to JSON instead, the [`serialization`](../readme.md#optionsserialization) option can be set to `'json'`.44+To limit messages to JSON instead, the [`serialization`](api.md#optionsserialization) option can be set to `'json'`.45 46 ```js47 const subprocess = execaNode({serialization: 'json'})`child.js`;48 ```6 unmodified linesmodified:docs/lines.md+11 added-11 removed
6 unmodified lines7 # 📃 Text lines8 9 ## Simple splitting10 11-If the [`lines`](../readme.md#optionslines) option is `true`, the output is split into lines, as an array of strings.11+If the [`lines`](api.md#optionslines) option is `true`, the output is split into lines, as an array of strings.12 13 ```js14 import {execa} from 'execa';15 4 unmodified lines20 ## Iteration21 22 ### Progressive splitting23 24-The subprocess' return value is an [async iterable](../readme.md#subprocesssymbolasynciterator). It iterates over the output's lines while the subprocess is still running.24+The subprocess' return value is an [async iterable](api.md#subprocesssymbolasynciterator). It iterates over the output's lines while the subprocess is still running.25 26 ```js27 for await (const line of execa`npm run build`) {28 if (line.includes('ERROR')) {1 unmodified line30 }31 }32 ```33 34-Alternatively, [`subprocess.iterable()`](../readme.md#subprocessiterablereadableoptions) can be called to pass [iterable options](../readme.md#readableoptions).34+Alternatively, [`subprocess.iterable()`](api.md#subprocessiterablereadableoptions) can be called to pass [iterable options](api.md#readableoptions).35 36-The iteration waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](../readme.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).36+The iteration waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](api.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).37 38 ```js39 for await (const line of execa`npm run build`.iterable())) {40 /* ... */1 unmodified line42 ```43 44 ### Stdout/stderr45 46-By default, the subprocess' [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) is used. The [`from`](../readme.md#readableoptionsfrom) iterable option can select a different file descriptor, such as [`'stderr'`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), [`'all'`](output.md#interleaved-output) or [`'fd3'`](output.md#additional-file-descriptors).46+By default, the subprocess' [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) is used. The [`from`](api.md#readableoptionsfrom) iterable option can select a different file descriptor, such as [`'stderr'`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), [`'all'`](output.md#interleaved-output) or [`'fd3'`](output.md#additional-file-descriptors).47 48 ```js49 for await (const stderrLine of execa`npm run build`.iterable({from: 'stderr'})) {50 /* ... */3 unmodified lines54 ## Newlines55 56 ### Final newline57 58-The final newline is stripped from the output's last line, unless the [`stripFinalNewline`](../readme.md#optionsstripfinalnewline) option is `false`.58+The final newline is stripped from the output's last line, unless the [`stripFinalNewline`](api.md#optionsstripfinalnewline) option is `false`.59 60 ```js61 const {stdout} = await execa({stripFinalNewline: false})`npm run build`;62 console.log(stdout.endsWith('\n')); // true63 ```64 65 ### Array of lines66 67-When using the [`lines`](#simple-splitting) option, newlines are stripped from each line, unless the [`stripFinalNewline`](../readme.md#optionsstripfinalnewline) option is `false`.67+When using the [`lines`](#simple-splitting) option, newlines are stripped from each line, unless the [`stripFinalNewline`](api.md#optionsstripfinalnewline) option is `false`.68 69 ```js70 // Each line now ends with '\n'.71 // The last `line` might or might not end with '\n', depending on the output.2 unmodified lines74 ```75 76 ### Iterable77 78-When [iterating](#progressive-splitting) over lines, newlines are stripped from each line, unless the [`preserveNewlines`](../readme.md#readableoptionspreservenewlines) iterable option is `true`.78+When [iterating](#progressive-splitting) over lines, newlines are stripped from each line, unless the [`preserveNewlines`](api.md#readableoptionspreservenewlines) iterable option is `true`.79 80-This option can also be used with [streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions) or [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions), providing the [`binary`](binary.md#streams) option is `false`.80+This option can also be used with [streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](api.md#subprocessreadablereadableoptions) or [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions), providing the [`binary`](binary.md#streams) option is `false`.81 82 ```js83 // `line` now ends with '\n'.84 // The last `line` might or might not end with '\n', depending on the output.3 unmodified lines88 ```89 90 ### Transforms91 92-When using [transforms](transform.md), newlines are stripped from each `line` argument, unless the [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) transform option is `true`.92+When using [transforms](transform.md), newlines are stripped from each `line` argument, unless the [`preserveNewlines`](api.md#transformoptionspreservenewlines) transform option is `true`.93 94 ```js95 // `line` now ends with '\n'.96 // The last `line` might or might not end with '\n', depending on the output.23 unmodified lines120 121 await execa({stdout: transform})`npm run build`;122 ```123 124-However, if the [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) transform option is `true`, multiple `yield`s produce a single line instead.124+However, if the [`preserveNewlines`](api.md#transformoptionspreservenewlines) transform option is `true`, multiple `yield`s produce a single line instead.125 126 ```js127 const transform = function * (line) {128 yield 'Important note: ';16 unmodified linesmodified:docs/node.md+1 added-1 removed
24 unmodified lines25 ```26 27 ## Node.js version28 29-[`get-node`](https://github.com/ehmicky/get-node) and the [`nodePath`](../readme.md#optionsnodepath) option can be used to run a specific Node.js version. Alternatively, [`nvexeca`](https://github.com/ehmicky/nvexeca) or [`nve`](https://github.com/ehmicky/nve) can be used.29+[`get-node`](https://github.com/ehmicky/get-node) and the [`nodePath`](api.md#optionsnodepath) option can be used to run a specific Node.js version. Alternatively, [`nvexeca`](https://github.com/ehmicky/nvexeca) or [`nve`](https://github.com/ehmicky/nve) can be used.30 31 ```js32 import {execaNode} from 'execa';33 import getNode from 'get-node';10 unmodified linesmodified:docs/output.md+12 added-12 removed
6 unmodified lines7 # 📢 Output8 9 ## Stdout and stderr10 11-The [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options redirect the subprocess output. They default to `'pipe'`, which returns the output using [`result.stdout`](../readme.md#resultstdout) and [`result.stderr`](../readme.md#resultstderr).11+The [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options redirect the subprocess output. They default to `'pipe'`, which returns the output using [`result.stdout`](api.md#resultstdout) and [`result.stderr`](api.md#resultstderr).12 13 ```js14 import {execa} from 'execa';15 36 unmodified lines52 ```53 54 ## Multiple targets55 56-The output can be redirected to multiple targets by setting the [`stdout`](../readme.md#optionsstdout) or [`stderr`](../readme.md#optionsstderr) option to an array of values. This also allows specifying multiple inputs with the [`stdin`](../readme.md#optionsstdin) option.56+The output can be redirected to multiple targets by setting the [`stdout`](api.md#optionsstdout) or [`stderr`](api.md#optionsstderr) option to an array of values. This also allows specifying multiple inputs with the [`stdin`](api.md#optionsstdin) option.57 58 The following example redirects `stdout` to both the [terminal](#terminal-output) and an `output.txt` [file](#file-output), while also retrieving its value [programmatically](#stdout-and-stderr).59 60 ```js4 unmodified lines65 When combining [`'inherit'`](#terminal-output) with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.66 67 ## Interleaved output68 69-If the [`all`](../readme.md#optionsall) option is `true`, [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) are combined:70-- [`result.all`](../readme.md#resultall): [`result.stdout`](../readme.md#resultstdout) + [`result.stderr`](../readme.md#resultstderr)71-- [`subprocess.all`](../readme.md#subprocessall): [`subprocess.stdout`](../readme.md#subprocessstdout) + [`subprocess.stderr`](../readme.md#subprocessstderr)69+If the [`all`](api.md#optionsall) option is `true`, [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) are combined:70+- [`result.all`](api.md#resultall): [`result.stdout`](api.md#resultstdout) + [`result.stderr`](api.md#resultstderr)71+- [`subprocess.all`](api.md#subprocessall): [`subprocess.stdout`](api.md#subprocessstdout) + [`subprocess.stderr`](api.md#subprocessstderr)72 73 `stdout` and `stderr` are guaranteed to interleave. However, for performance reasons, the subprocess might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This can prevent proper interleaving.74 75 For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.21 unmodified lines97 ```98 99 ## Stdout/stderr-specific options100 101-Some options are related to the subprocess output: [`verbose`](../readme.md#optionsverbose), [`lines`](../readme.md#optionslines), [`stripFinalNewline`](../readme.md#optionsstripfinalnewline), [`buffer`](../readme.md#optionsbuffer), [`maxBuffer`](../readme.md#optionsmaxbuffer). By default, those options apply to all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) ([`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), and [others](#additional-file-descriptors)). A plain object can be passed instead to apply them to only `stdout`, `stderr`, [`fd3`](#additional-file-descriptors), etc.101+Some options are related to the subprocess output: [`verbose`](api.md#optionsverbose), [`lines`](api.md#optionslines), [`stripFinalNewline`](api.md#optionsstripfinalnewline), [`buffer`](api.md#optionsbuffer), [`maxBuffer`](api.md#optionsmaxbuffer). By default, those options apply to all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) ([`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), and [others](#additional-file-descriptors)). A plain object can be passed instead to apply them to only `stdout`, `stderr`, [`fd3`](#additional-file-descriptors), etc.102 103 ```js104 // Same value for stdout and stderr105 await execa({verbose: 'full'})`npm run build`;3 unmodified lines109 ```110 111 ## Additional file descriptors112 113-The [`stdio`](../readme.md#optionsstdio) option is an array combining [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and any other file descriptor. It is useful when using additional [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) beyond the [standard ones](https://en.wikipedia.org/wiki/Standard_streams), either for [input](input.md#additional-file-descriptors) or output.113+The [`stdio`](api.md#optionsstdio) option is an array combining [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and any other file descriptor. It is useful when using additional [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) beyond the [standard ones](https://en.wikipedia.org/wiki/Standard_streams), either for [input](input.md#additional-file-descriptors) or output.114 115-[`result.stdio`](../readme.md#resultstdio) can be used to retrieve some output from any file descriptor, as opposed to only [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr).115+[`result.stdio`](api.md#resultstdio) can be used to retrieve some output from any file descriptor, as opposed to only [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr).116 117 ```js118 // Retrieve output from file descriptor number 3119 const {stdio} = await execa({3 unmodified lines123 ```124 125 ## Shortcut126 127-The [`stdio`](../readme.md#optionsstdio) option can also be a single value [`'pipe'`](#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore'`](#ignore-output) or [`'inherit'`](#terminal-output). This is a shortcut for setting that same value with the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options.127+The [`stdio`](api.md#optionsstdio) option can also be a single value [`'pipe'`](#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore'`](#ignore-output) or [`'inherit'`](#terminal-output). This is a shortcut for setting that same value with the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options.128 129 ```js130 await execa({stdio: 'ignore'})`npm run build`;131 // Same as:1 unmodified line133 ```134 135 ## Big output136 137-To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](../readme.md#optionsmaxbuffer) option. It defaults to 100MB.137+To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.138 139-When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](../readme.md#resultismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](../readme.md#resultstdout) and [`error.stderr`](../readme.md#resultstderr).139+When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#resultismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout) and [`error.stderr`](api.md#resultstderr).140 141 This is measured:142 - By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).143 - If the [`encoding`](binary.md#encoding) option is `'buffer'`: in bytes.15 unmodified lines159 ```160 161 ## Low memory162 163-When the [`buffer`](../readme.md#optionsbuffer) option is `false`, [`result.stdout`](../readme.md#resultstdout), [`result.stderr`](../readme.md#resultstderr), [`result.all`](../readme.md#resultall) and [`result.stdio[*]`](../readme.md#resultstdio) properties are not set.163+When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall) and [`result.stdio[*]`](api.md#resultstdio) properties are not set.164 165 This prevents high memory consumption when the output is big. However, the output must be either ignored, [redirected](#file-output) or [streamed](streams.md). If streamed, this should be done right away to avoid missing any data.166 167 <hr>4 unmodified linesmodified:docs/pipe.md+7 added-7 removed
33 unmodified lines34 ```35 36 ## Options37 38-[Options](../readme.md#options) can be passed to either the source or the destination subprocess. Some [pipe-specific options](../readme.md#pipeoptions) can also be set by the destination subprocess.38+[Options](api.md#options) can be passed to either the source or the destination subprocess. Some [pipe-specific options](api.md#pipeoptions) can also be set by the destination subprocess.39 40 ```js41 const {stdout} = await execa('npm', ['run', 'build'], subprocessOptions)42 .pipe('head', ['-n', '2'], subprocessOrPipeOptions);11 unmodified lines54 ```55 56 ## Result57 58-When both subprocesses succeed, the [`result`](../readme.md#result) of the destination subprocess is returned. The [`result`](../readme.md#result) of the source subprocess is available in a [`result.pipedFrom`](../readme.md#resultpipedfrom) array.58+When both subprocesses succeed, the [`result`](api.md#result) of the destination subprocess is returned. The [`result`](api.md#result) of the source subprocess is available in a [`result.pipedFrom`](api.md#resultpipedfrom) array.59 60 ```js61 const destinationResult = await execa`npm run build`62 .pipe`head -n 2`;4 unmodified lines67 ```68 69 ## Errors70 71-When either subprocess fails, `subprocess.pipe()` is rejected with that subprocess' error. If the destination subprocess fails, [`error.pipedFrom`](../readme.md#resultpipedfrom) includes the source subprocess' result, which is useful for debugging.71+When either subprocess fails, `subprocess.pipe()` is rejected with that subprocess' error. If the destination subprocess fails, [`error.pipedFrom`](api.md#resultpipedfrom) includes the source subprocess' result, which is useful for debugging.72 73 ```js74 try {75 await execa`npm run build`42 unmodified lines118 ```119 120 ## Source file descriptor121 122-By default, the source's [`stdout`](../readme.md#subprocessstdout) is used, but this can be changed using the [`from`](../readme.md#pipeoptionsfrom) piping option.122+By default, the source's [`stdout`](api.md#subprocessstdout) is used, but this can be changed using the [`from`](api.md#pipeoptionsfrom) piping option.123 124 ```js125 await execa`npm run build`126 .pipe({from: 'stderr'})`head -n 2`;127 ```128 129 ## Destination file descriptor130 131-By default, the destination's [`stdin`](../readme.md#subprocessstdin) is used, but this can be changed using the [`to`](../readme.md#pipeoptionsto) piping option.131+By default, the destination's [`stdin`](api.md#subprocessstdin) is used, but this can be changed using the [`to`](api.md#pipeoptionsto) piping option.132 133 ```js134 await execa`npm run build`135 .pipe({to: 'fd3'})`./log-remotely.js`;136 ```137 138 ## Unpipe139 140-Piping can be stopped using the [`unpipeSignal`](../readme.md#pipeoptionsunpipesignal) piping option.140+Piping can be stopped using the [`unpipeSignal`](api.md#pipeoptionsunpipesignal) piping option.141 142-The [`subprocess.pipe()`](../readme.md#subprocesspipefile-arguments-options) method will be rejected with a cancelation error. However, each subprocess will keep running.142+The [`subprocess.pipe()`](api.md#subprocesspipefile-arguments-options) method will be rejected with a cancelation error. However, each subprocess will keep running.143 144 ```js145 const abortController = new AbortController();146 21 unmodified linesmodified:docs/scripts.md+2 added-2 removed
8 unmodified lines9 ## Script files10 11 [Scripts](https://en.wikipedia.org/wiki/Shell_script) are Node.js files executing a series of commands. While those used to be written with a shell language like [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), libraries like Execa provide with a better, modern experience.12 13-Scripts use [`$`](../readme.md#file-arguments-options) instead of [`execa`](../readme.md#execafile-arguments-options). The only difference is that `$` includes script-friendly default options: [`stdin: 'inherit'`](input.md#terminal-input) and [`preferLocal: true`](environment.md#local-binaries).13+Scripts use [`$`](api.md#file-arguments-options) instead of [`execa`](api.md#execafile-arguments-options). The only difference is that `$` includes script-friendly default options: [`stdin: 'inherit'`](input.md#terminal-input) and [`preferLocal: true`](environment.md#local-binaries).14 15 [More info about the difference between Execa, Bash and zx.](bash.md)16 17 ```js17 unmodified lines35 ```36 37 ## Template string syntax38 39-Just like [`execa`](../readme.md#execafile-arguments-options), [`$`](../readme.md#file-arguments-options) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).39+Just like [`execa`](api.md#execafile-arguments-options), [`$`](api.md#file-arguments-options) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).40 41 Conversely, the template string syntax can be used outside of script files: `$` is not required to use that syntax. For example, `execa` [can use it too](execution.md#template-string-syntax).42 43 ```js11 unmodified linesmodified:docs/shell.md+1 added-1 removed
21 unmodified lines22 ```23 24 ## OS-specific shell25 26-When the [`shell`](../readme.md#optionsshell) option is `true`, `sh` is used on Unix and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows.26+When the [`shell`](api.md#optionsshell) option is `true`, `sh` is used on Unix and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows.27 28 `sh` and `cmd.exe` syntaxes are very different. Therefore, this is usually not useful.29 30 ```js8 unmodified linesmodified:docs/streams.md+7 added-7 removed
32 unmodified lines33 ```34 35 ### File descriptors36 37-When passing a Node.js stream to the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) or [`stderr`](../readme.md#optionsstderr) option, that stream must have an underlying file or socket, such as the streams created by the [`fs`](https://nodejs.org/api/fs.html#filehandlecreatereadstreamoptions), [`net`](https://nodejs.org/api/net.html#new-netsocketoptions) or [`http`](https://nodejs.org/api/http.html#class-httpincomingmessage) core modules. Otherwise the following error is thrown.37+When passing a Node.js stream to the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) or [`stderr`](api.md#optionsstderr) option, that stream must have an underlying file or socket, such as the streams created by the [`fs`](https://nodejs.org/api/fs.html#filehandlecreatereadstreamoptions), [`net`](https://nodejs.org/api/net.html#new-netsocketoptions) or [`http`](https://nodejs.org/api/http.html#class-httpincomingmessage) core modules. Otherwise the following error is thrown.38 39 ```40 TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.41 ```42 43 This limitation can be worked around by either:44-- Using the [`input`](../readme.md#optionsinput) option instead of the [`stdin`](../readme.md#optionsstdin) option.44+- Using the [`input`](api.md#optionsinput) option instead of the [`stdin`](api.md#optionsstdin) option.45 - Passing a [web stream](#web-streams).46 - Passing [`[nodeStream, 'pipe']`](output.md#multiple-targets) instead of `nodeStream`.47 48 ## Web streams18 unmodified lines67 ```68 69 ## Manual streaming70 71-[`subprocess.stdin`](../readme.md#subprocessstdin) is a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) stream and [`subprocess.stdout`](../readme.md#subprocessstdout)/[`subprocess.stderr`](../readme.md#subprocessstderr)/[`subprocess.all`](../readme.md#subprocessall) are Node.js [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) streams.71+[`subprocess.stdin`](api.md#subprocessstdin) is a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) stream and [`subprocess.stdout`](api.md#subprocessstdout)/[`subprocess.stderr`](api.md#subprocessstderr)/[`subprocess.all`](api.md#subprocessall) are Node.js [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) streams.72 73 They can be used to stream input/output manually. This is intended for advanced situations. In most cases, the following simpler solutions can be used instead:74 - [`result.stdout`](output.md#stdout-and-stderr), [`result.stderr`](output.md#stdout-and-stderr) or [`result.stdio`](output.md#additional-file-descriptors).75-- The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) or [`stdio`](../readme.md#optionsstdio) options.75+- The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) or [`stdio`](api.md#optionsstdio) options.76 - [`subprocess.iterable()`](lines.md#progressive-splitting).77 - [`subprocess.pipe()`](pipe.md).78 79 ## Converting a subprocess to a stream80 81 ### Convert82 83-The [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions) methods convert the subprocess to a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable), [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) and [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream.83+The [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions) methods convert the subprocess to a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable), [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) and [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream.84 85 This is useful when using a library or API that expects Node.js streams as arguments. In every other situation, the simpler solutions described [above](#manual-streaming) can be used instead.86 87 ```js5 unmodified lines93 ```94 95 ### Different file descriptor96 97-By default, [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions) methods use [`stdin`](../readme.md#subprocessstdin) and [`stdout`](../readme.md#subprocessstdout). This can be changed using the [`from`](../readme.md#readableoptionsfrom) and [`to`](../readme.md#writableoptionsto) options.97+By default, [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions) methods use [`stdin`](api.md#subprocessstdin) and [`stdout`](api.md#subprocessstdout). This can be changed using the [`from`](api.md#readableoptionsfrom) and [`to`](api.md#writableoptionsto) options.98 99 ```js100 const readable = execa`npm run scaffold`.readable({from: 'stderr'});101 3 unmodified lines105 ```106 107 ### Error handling108 109-When using [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) or [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions), 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](errors.md). This differs from [`subprocess.stdin`](../readme.md#subprocessstdin), [`subprocess.stdout`](../readme.md#subprocessstdout) and [`subprocess.stderr`](../readme.md#subprocessstderr)'s behavior.109+When using [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) or [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions), 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](errors.md). This differs from [`subprocess.stdin`](api.md#subprocessstdin), [`subprocess.stdout`](api.md#subprocessstdout) and [`subprocess.stderr`](api.md#subprocessstderr)'s behavior.110 111 This means you do not need to `await` the subprocess' [promise](execution.md#result). On the other hand, you (or the library using the stream) do need to both consume the stream, and handle its `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.112 113 <hr>4 unmodified linesmodified:docs/termination.md+14 added-14 removed
6 unmodified lines7 # 🏁 Termination8 9 ## Canceling10 11-The [`cancelSignal`](../readme.md#optionscancelsignal) option can be used to cancel a subprocess. When [`abortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), a [`SIGTERM` signal](#default-signal) is sent to the subprocess.11+The [`cancelSignal`](api.md#optionscancelsignal) option can be used to cancel a subprocess. When [`abortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), a [`SIGTERM` signal](#default-signal) is sent to the subprocess.12 13 ```js14 import {execa} from 'execa';15 15 unmodified lines31 ```32 33 ## Timeout34 35-If the subprocess lasts longer than the [`timeout`](../readme.md#optionstimeout) option, a [`SIGTERM` signal](#default-signal) is sent to it.35+If the subprocess lasts longer than the [`timeout`](api.md#optionstimeout) option, a [`SIGTERM` signal](#default-signal) is sent to it.36 37 ```js38 try {39 await execa({timeout: 5000})`npm run build`;8 unmodified lines48 49 ## Current process exit50 51 If the current process exits, the subprocess is automatically [terminated](#default-signal) unless either:52-- The [`cleanup`](../readme.md#optionscleanup) option is `false`.53-- The subprocess is run in the background using the [`detached`](../readme.md#optionsdetached) option.52+- The [`cleanup`](api.md#optionscleanup) option is `false`.53+- The subprocess is run in the background using the [`detached`](api.md#optionsdetached) option.54 - The current process was terminated abruptly, for example, with [`SIGKILL`](#sigkill) as opposed to [`SIGTERM`](#sigterm) or a successful exit.55 56 ## Signal termination57 58-[`subprocess.kill()`](../readme.md#subprocesskillsignal-error) sends a [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) to the subprocess. This is an inter-process message handled by the OS. Most (but [not all](https://github.com/ehmicky/human-signals#action)) signals terminate the subprocess.58+[`subprocess.kill()`](api.md#subprocesskillsignal-error) sends a [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) to the subprocess. This is an inter-process message handled by the OS. Most (but [not all](https://github.com/ehmicky/human-signals#action)) signals terminate the subprocess.59 60 [More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)61 62 ### SIGTERM29 unmodified lines92 Other signals can be passed as argument. However, most other signals do not fully [work on Windows](https://github.com/ehmicky/cross-platform-node-guide/blob/main/docs/6_networking_ipc/signals.md#cross-platform-signals).93 94 ### Default signal95 96-The [`killSignal`](../readme.md#optionskillsignal) option sets the default signal used by [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) and the following options: [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) and [`cleanup`](#current-process-exit). It is [`SIGTERM`](#sigterm) by default.96+The [`killSignal`](api.md#optionskillsignal) option sets the default signal used by [`subprocess.kill()`](api.md#subprocesskillsignal-error) and the following options: [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) and [`cleanup`](#current-process-exit). It is [`SIGTERM`](#sigterm) by default.97 98 ```js99 const subprocess = execa({killSignal: 'SIGKILL'})`npm run build`;100 subprocess.kill(); // Forceful termination101 ```102 103 ### Signal name and description104 105-When a subprocess was terminated by a signal, [`error.isTerminated`](../readme.md#resultisterminated) is `true`.105+When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#resultisterminated) is `true`.106 107-Also, [`error.signal`](../readme.md#resultsignal) and [`error.signalDescription`](../readme.md#resultsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).107+Also, [`error.signal`](api.md#resultsignal) and [`error.signalDescription`](api.md#resultsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).108 109 ```js110 try {111 await execa`npm run build`;10 unmodified lines122 ## Forceful termination123 124 If the subprocess is terminated but does not exit, [`SIGKILL`](#sigkill) is automatically sent to forcefully terminate it.125 126-The grace period is set by the [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option, which is 5 seconds by default. This feature can be disabled with `false`.126+The grace period is set by the [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option, which is 5 seconds by default. This feature can be disabled with `false`.127 128 This works when the subprocess is terminated by either:129-- Calling [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) with no arguments.129+- Calling [`subprocess.kill()`](api.md#subprocesskillsignal-error) with no arguments.130 - The [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) or [`cleanup`](#current-process-exit) option.131 132 This does not work when the subprocess is terminated by either:133-- Calling [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) with a specific signal.134-- Calling [`process.kill(subprocess.pid)`](../readme.md#subprocesspid).133+- Calling [`subprocess.kill()`](api.md#subprocesskillsignal-error) with a specific signal.134+- Calling [`process.kill(subprocess.pid)`](api.md#subprocesspid).135 - Sending a termination signal [from another process](#inter-process-termination).136 137 Also, 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.138 4 unmodified lines143 ```144 145 ## Inter-process termination146 147-[`subprocess.kill()`](../readme.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process (for example, a terminal), its [`subprocess.pid`](../readme.md#subprocesspid) can be used instead.147+[`subprocess.kill()`](api.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process (for example, a terminal), its [`subprocess.pid`](api.md#subprocesspid) can be used instead.148 149 ```js150 const subprocess = execa`npm run build`;151 console.log('PID:', subprocess.pid); // PID: 65135 unmodified lines157 ```158 159 ## Error message and stack trace160 161-When terminating a subprocess, it is possible to include an error message and stack trace by using [`subprocess.kill(error)`](../readme.md#subprocesskillerror). The `error` argument will be available at [`error.cause`](../readme.md#errorcause).161+When terminating a subprocess, it is possible to include an error message and stack trace by using [`subprocess.kill(error)`](api.md#subprocesskillerror). The `error` argument will be available at [`error.cause`](api.md#errorcause).162 163 ```js164 try {165 const subprocess = execa`npm run build`;20 unmodified linesmodified:docs/transform.md+9 added-9 removed
6 unmodified lines7 # 🧙 Transforms8 9 ## Summary10 11-Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) or a [transform options object](../readme.md#transform-options) to the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) or [`stdio`](../readme.md#optionsstdio) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).11+Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) or a [transform options object](api.md#transform-options) to the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) or [`stdio`](api.md#optionsstdio) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).12 13 ```js14 import {execa} from 'execa';15 8 unmodified lines24 25 ## Difference with iteration26 27 Transforms operate one `line` at a time, just like [`subprocess.iterable()`](lines.md#progressive-splitting). However, unlike iteration, transforms:28-- Modify the subprocess' [output](../readme.md#resultstdout) and [streams](../readme.md#subprocessstdout).28+- Modify the subprocess' [output](api.md#resultstdout) and [streams](api.md#subprocessstdout).29 - Can apply to the subprocess' input.30 - Are defined using a [generator function](#summary), [`Duplex`](#duplextransform-streams) stream, Node.js [`Transform`](#duplextransform-streams) stream or web [`TransformStream`](#duplextransform-streams).31 32 ## Filtering12 unmodified lines45 ```46 47 ## Object mode48 49-By default, [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr)'s transforms must return a string or an `Uint8Array`. However, if the [`objectMode`](../readme.md#transformoptionsobjectmode) transform option is `true`, any type can be returned instead, except `null` or `undefined`. The subprocess' [`result.stdout`](../readme.md#resultstdout)/[`result.stderr`](../readme.md#resultstderr) will be an array of values.49+By default, [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr)'s transforms must return a string or an `Uint8Array`. However, if the [`objectMode`](api.md#transformoptionsobjectmode) transform option is `true`, any type can be returned instead, except `null` or `undefined`. The subprocess' [`result.stdout`](api.md#resultstdout)/[`result.stderr`](api.md#resultstderr) will be an array of values.50 51 ```js52 const transform = function * (line) {53 yield JSON.parse(line);4 unmodified lines58 console.log(stdout); // {...object}59 }60 ```61 62-[`stdin`](../readme.md#optionsstdin) can also use `objectMode: true`.62+[`stdin`](api.md#optionsstdin) can also use `objectMode: true`.63 64 ```js65 const transform = function * (line) {66 yield JSON.stringify(line);4 unmodified lines71 ```72 73 ## Sharing state74 75-State can be shared between calls of the [`transform`](../readme.md#transformoptionstransform) and [`final`](../readme.md#transformoptionsfinal) functions.75+State can be shared between calls of the [`transform`](api.md#transformoptionstransform) and [`final`](api.md#transformoptionsfinal) functions.76 77 ```js78 let count = 0;79 4 unmodified lines84 ```85 86 ## Finalizing87 88-To create additional lines after the last one, a [`final`](../readme.md#transformoptionsfinal) generator function can be used.88+To create additional lines after the last one, a [`final`](api.md#transformoptionsfinal) generator function can be used.89 90 ```js91 let count = 0;92 13 unmodified lines106 ## Duplex/Transform streams107 108 A [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream, Node.js [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream or web [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) can be used instead of a generator function.109 110-Like generator functions, web `TransformStream` can be passed either directly or as a [`{transform}` plain object](../readme.md#transform-options). But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.110+Like generator functions, web `TransformStream` can be passed either directly or as a [`{transform}` plain object](api.md#transform-options). But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.111 112-The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](../readme.md#transformoptionsbinary) nor [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) options.112+The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](api.md#transformoptionsbinary) nor [`preserveNewlines`](api.md#transformoptionspreservenewlines) options.113 114 ```js115 import {createGzip} from 'node:zlib';116 import {execa} from 'execa';14 unmodified lines131 ```132 133 ## Combining134 135-The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and [`stdio`](../readme.md#optionsstdio) options can accept [an array of values](output.md#multiple-targets). While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `'inherit'`.135+The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and [`stdio`](api.md#optionsstdio) options can accept [an array of values](output.md#multiple-targets). While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `'inherit'`.136 137 ```js138 await execa({stdout: [transform, 'inherit']})`npm run build`;139 ```18 unmodified linesmodified:docs/windows.md+5 added-5 removed
24 unmodified lines25 Although Windows does not natively support shebangs, Execa adds support for them.26 27 ## Signals28 29-Only few [signals](termination.md#other-signals) work on Windows with Node.js: [`SIGTERM`](termination.md#sigterm), [`SIGKILL`](termination.md#sigkill) and [`SIGINT`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT). Also, sending signals from other processes is [not supported](termination.md#signal-name-and-description). Finally, the [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option [is a noop](termination.md#forceful-termination) on Windows.29+Only few [signals](termination.md#other-signals) work on Windows with Node.js: [`SIGTERM`](termination.md#sigterm), [`SIGKILL`](termination.md#sigkill) and [`SIGINT`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT). Also, sending signals from other processes is [not supported](termination.md#signal-name-and-description). Finally, the [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option [is a noop](termination.md#forceful-termination) on Windows.30 31 ## Asynchronous I/O32 33-The default value for the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options is [`'pipe'`](output.md#stdout-and-stderr). This returns the output as [`result.stdout`](../readme.md#resultstdout) and [`result.stderr`](../readme.md#resultstderr) and allows for [manual streaming](streams.md#manual-streaming).33+The default value for the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options is [`'pipe'`](output.md#stdout-and-stderr). This returns the output as [`result.stdout`](api.md#resultstdout) and [`result.stderr`](api.md#resultstderr) and allows for [manual streaming](streams.md#manual-streaming).34 35 Instead of `'pipe'`, `'overlapped'` can be used instead to use [asynchronous I/O](https://learn.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o) under-the-hood on Windows, instead of the default behavior which is synchronous. On other platforms, asynchronous I/O is always used, so `'overlapped'` behaves the same way as `'pipe'`.36 37 ## `cmd.exe` escaping38 39-If the [`windowsVerbatimArguments`](../readme.md#optionswindowsverbatimarguments) option is `false`, the [command arguments](input.md#command-arguments) are automatically escaped on Windows. When using a [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) [shell](../readme.md#optionsshell), this is `true` by default instead.39+If the [`windowsVerbatimArguments`](api.md#optionswindowsverbatimarguments) option is `false`, the [command arguments](input.md#command-arguments) are automatically escaped on Windows. When using a [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) [shell](api.md#optionsshell), this is `true` by default instead.40 41 This is ignored on other platforms: those are [automatically escaped](escaping.md) by default.42 43 ## Console window44 45-If the [`windowsHide`](../readme.md#optionswindowshide) option is `false`, the subprocess is run in a new console window. This is necessary to make [`SIGINT` work](https://github.com/nodejs/node/issues/29837) on Windows, and to prevent subprocesses not being cleaned up in [some specific situations](https://github.com/sindresorhus/execa/issues/433).45+If the [`windowsHide`](api.md#optionswindowshide) option is `false`, the subprocess is run in a new console window. This is necessary to make [`SIGINT` work](https://github.com/nodejs/node/issues/29837) on Windows, and to prevent subprocesses not being cleaned up in [some specific situations](https://github.com/sindresorhus/execa/issues/433).46 47 ## UID and GID48 49-By default, subprocesses are run using the current [user](https://en.wikipedia.org/wiki/User_identifier) and [group](https://en.wikipedia.org/wiki/Group_identifier). The [`uid`](../readme.md#optionsuid) and [`gid`](../readme.md#optionsgid) options can be used to set a different user or group.49+By default, subprocesses are run using the current [user](https://en.wikipedia.org/wiki/User_identifier) and [group](https://en.wikipedia.org/wiki/Group_identifier). The [`uid`](api.md#optionsuid) and [`gid`](api.md#optionsgid) options can be used to set a different user or group.50 51 However, since Windows uses a different permission model, those options throw.52 53 <hr>4 unmodified linesmodified:readme.md+1 added-1017 removed
93 unmodified lines94 - 📞 [Inter-process communication](docs/ipc.md)95 - 🐛 [Debugging](docs/debugging.md)96 - 📎 [Windows](docs/windows.md)97 - 🔍 [Difference with Bash and zx](docs/bash.md)98+- 📔 [API reference](docs/api.md)99 100 ## Usage101 102 ### Promise interface196 unmodified lines299 */300 }301 ```302 302-## API303-304-### Methods305-306-#### execa(file, arguments?, options?)307-308-`file`: `string | URL`\309-`arguments`: `string[]`\310-`options`: [`Options`](#options)\311-_Returns_: [`Subprocess`](#subprocess)312-313-Executes a command using `file ...arguments`.314-315-More info on the [syntax](docs/execution.md#array-syntax) and [escaping](docs/escaping.md#array-syntax).316-317-#### execa\`command\`318-#### execa(options)\`command\`319-320-`command`: `string`\321-`options`: [`Options`](#options)\322-_Returns_: [`Subprocess`](#subprocess)323-324-Executes a command. `command` is a [template string](docs/execution.md#template-string-syntax) that includes both the `file` and its `arguments`.325-326-More info on the [syntax](docs/execution.md#template-string-syntax) and [escaping](docs/escaping.md#template-string-syntax).327-328-#### execa(options)329-330-`options`: [`Options`](#options)\331-_Returns_: [`execa`](#execafile-arguments-options)332-333-Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.334-335-[More info.](docs/execution.md#globalshared-options)336-337-#### execaSync(file, arguments?, options?)338-#### execaSync\`command\`339-340-Same as [`execa()`](#execafile-arguments-options) but synchronous.341-342-Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.343-344-[More info.](docs/execution.md#synchronous-execution)345-346-#### $(file, arguments?, options?)347-348-`file`: `string | URL`\349-`arguments`: `string[]`\350-`options`: [`Options`](#options)\351-_Returns_: [`Subprocess`](#subprocess)352-353-Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](docs/scripts.md#script-files).354-355-Just like `execa()`, this can use the [template string syntax](docs/execution.md#template-string-syntax) or [bind options](docs/execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.356-357-This is the preferred method when executing multiple commands in a script file.358-359-[More info.](docs/scripts.md)360-361-#### execaNode(scriptPath, arguments?, options?)362-363-`scriptPath`: `string | URL`\364-`arguments`: `string[]`\365-`options`: [`Options`](#options)\366-_Returns_: [`Subprocess`](#subprocess)367-368-Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.369-Executes a Node.js file using `node scriptPath ...arguments`.370-371-Just like `execa()`, this can use the [template string syntax](docs/execution.md#template-string-syntax) or [bind options](docs/execution.md#globalshared-options).372-373-This is the preferred method when executing Node.js files.374-375-[More info.](docs/node.md)376-377-#### execaCommand(command, options?)378-379-`command`: `string`\380-`options`: [`Options`](#options)\381-_Returns_: [`Subprocess`](#subprocess)382-383-Executes a command. `command` is a string that includes both the `file` and its `arguments`.384-385-This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.386-387-Just like `execa()`, this can [bind options](docs/execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.388-389-[More info.](docs/escaping.md#user-defined-input)390-391-### Subprocess392-393-The return value of all [asynchronous methods](#methods) is both:394-- a `Promise` resolving or rejecting with a subprocess [`result`](#result).395-- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.396-397-[More info.](docs/execution.md#subprocess)398-399-#### subprocess\[Symbol.asyncIterator\]()400-401-_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)402-403-Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.404-405-[More info.](docs/lines.md#progressive-splitting)406-407-#### subprocess.iterable(readableOptions?)408-409-`readableOptions`: [`ReadableOptions`](#readableoptions)\410-_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)411-412-Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.413-414-[More info.](docs/lines.md#progressive-splitting)415-416-#### subprocess.pipe(file, arguments?, options?)417-418-`file`: `string | URL`\419-`arguments`: `string[]`\420-`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\421-_Returns_: [`Promise<Result>`](#result)422-423-[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' [`stdout`](#subprocessstdout) to a second Execa subprocess' [`stdin`](#subprocessstdin). This resolves with that second subprocess' [result](#result). If either subprocess is rejected, this is rejected with that subprocess' [error](#execaerror) instead.424-425-This 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.426-427-[More info.](docs/pipe.md#array-syntax)428-429-#### subprocess.pipe\`command\`430-#### subprocess.pipe(options)\`command\`431-432-`command`: `string`\433-`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\434-_Returns_: [`Promise<Result>`](#result)435-436-Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](docs/execution.md#template-string-syntax).437-438-[More info.](docs/pipe.md#template-string-syntax)439-440-#### subprocess.pipe(secondSubprocess, pipeOptions?)441-442-`secondSubprocess`: [`execa()` return value](#subprocess)\443-`pipeOptions`: [`PipeOptions`](#pipeoptions)\444-_Returns_: [`Promise<Result>`](#result)445-446-Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#subprocess) of another [`execa()`](#execafile-arguments-options) call instead.447-448-[More info.](docs/pipe.md#advanced-syntax)449-450-##### pipeOptions451-452-Type: `object`453-454-##### pipeOptions.from455-456-Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\457-Default: `"stdout"`458-459-Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.460-461-`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.462-463-[More info.](docs/pipe.md#source-file-descriptor)464-465-##### pipeOptions.to466-467-Type: `"stdin" | "fd3" | "fd4" | ...`\468-Default: `"stdin"`469-470-Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.471-472-[More info.](docs/pipe.md#destination-file-descriptor)473-474-##### pipeOptions.unpipeSignal475-476-Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)477-478-Unpipe the subprocess when the signal aborts.479-480-[More info.](docs/pipe.md#unpipe)481-482-#### subprocess.kill(signal, error?)483-#### subprocess.kill(error?)484-485-`signal`: `string | number`\486-`error`: `Error`\487-_Returns_: `boolean`488-489-Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#optionskillsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#resultisterminated) the subprocess.490-491-This returns `false` when the signal could not be sent, for example when the subprocess has already exited.492-493-When an error is passed as argument, it is set to the subprocess' [`error.cause`](#errorcause). The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).494-495-[More info.](docs/termination.md)496-497-#### subprocess.pid498-499-_Type_: `number | undefined`500-501-Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).502-503-This is `undefined` if the subprocess failed to spawn.504-505-[More info.](docs/termination.md#inter-process-termination)506-507-#### subprocess.send(message)508-509-`message`: `unknown`\510-_Returns_: `boolean`511-512-Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.513-The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).514-515-This returns `true` on success.516-517-This requires the [`ipc`](#optionsipc) option to be `true`.518-519-[More info.](docs/ipc.md#exchanging-messages)520-521-#### subprocess.on('message', (message) => void)522-523-`message`: `unknown`524-525-Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.526-The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).527-528-This requires the [`ipc`](#optionsipc) option to be `true`.529-530-[More info.](docs/ipc.md#exchanging-messages)531-532-#### subprocess.stdin533-534-Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)535-536-The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.537-538-This is `null` if the [`stdin`](#optionsstdin) option is set to [`'inherit'`](docs/input.md#terminal-input), [`'ignore'`](docs/input.md#ignore-input), [`Readable`](docs/streams.md#input) or [`integer`](docs/input.md#terminal-input).539-540-[More info.](docs/streams.md#manual-streaming)541-542-#### subprocess.stdout543-544-Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)545-546-The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.547-548-This is `null` if the [`stdout`](#optionsstdout) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.549-550-[More info.](docs/streams.md#manual-streaming)551-552-#### subprocess.stderr553-554-Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)555-556-The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.557-558-This is `null` if the [`stderr`](#optionsstdout) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.559-560-[More info.](docs/streams.md#manual-streaming)561-562-#### subprocess.all563-564-Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)565-566-Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).567-568-This requires the [`all`](#optionsall) option to be `true`.569-570-This is `undefined` if [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.571-572-More info on [interleaving](docs/output.md#interleaved-output) and [streaming](docs/streams.md#manual-streaming).573-574-#### subprocess.stdio575-576-Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)577-578-The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.579-580-Each array item is `null` if the corresponding [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Stream`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.581-582-[More info.](docs/streams.md#manual-streaming)583-584-#### subprocess.readable(readableOptions?)585-586-`readableOptions`: [`ReadableOptions`](#readableoptions)\587-_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream588-589-Converts the subprocess to a readable stream.590-591-[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)592-593-##### readableOptions594-595-Type: `object`596-597-##### readableOptions.from598-599-Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\600-Default: `"stdout"`601-602-Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.603-604-`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.605-606-[More info.](docs/streams.md#different-file-descriptor)607-608-##### readableOptions.binary609-610-Type: `boolean`\611-Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)612-613-If `false`, iterates over lines. Each line is a string.614-615-If `true`, iterates over arbitrary chunks of data. Each line is an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) (with [`subprocess.iterable()`](#subprocessiterablereadableoptions)) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)).616-617-This is always `true` when the [`encoding`](#optionsencoding) option is binary.618-619-More info for [iterables](docs/binary.md#iterable) and [streams](docs/binary.md#streams).620-621-##### readableOptions.preserveNewlines622-623-Type: `boolean`\624-Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)625-626-If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.627-628-[More info.](docs/lines.md#iterable)629-630-#### subprocess.writable(writableOptions?)631-632-`writableOptions`: [`WritableOptions`](#writableoptions)\633-_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream634-635-Converts the subprocess to a writable stream.636-637-[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)638-639-##### writableOptions640-641-Type: `object`642-643-##### writableOptions.to644-645-Type: `"stdin" | "fd3" | "fd4" | ...`\646-Default: `"stdin"`647-648-Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.649-650-[More info.](docs/streams.md#different-file-descriptor)651-652-#### subprocess.duplex(duplexOptions?)653-654-`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\655-_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream656-657-Converts the subprocess to a duplex stream.658-659-[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)660-661-### Result662-663-Type: `object`664-665-[Result](docs/execution.md#result) of a subprocess execution.666-667-When the subprocess [fails](docs/errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.668-669-#### result.stdout670-671-Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`672-673-The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).674-675-This is `undefined` if the [`stdout`](#optionsstdout) option is set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.676-677-This is an array if the [`lines`](#optionslines) option is `true`, or if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).678-679-[More info.](docs/output.md#stdout-and-stderr)680-681-#### result.stderr682-683-Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`684-685-The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).686-687-This is `undefined` if the [`stderr`](#optionsstderr) option is set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.688-689-This is an array if the [`lines`](#optionslines) option is `true`, or if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).690-691-[More info.](docs/output.md#stdout-and-stderr)692-693-#### result.all694-695-Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`696-697-The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.698-699-This requires the [`all`](#optionsall) option to be `true`.700-701-This is `undefined` if both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.702-703-This is an array if the [`lines`](#optionslines) option is `true`, or if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).704-705-[More info.](docs/output.md#interleaved-output)706-707-#### result.stdio708-709-Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`710-711-The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).712-713-Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.714-715-Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).716-717-[More info.](docs/output.md#additional-file-descriptors)718-719-#### result.pipedFrom720-721-Type: [`Array<Result | ExecaError>`](#result)722-723-[Results](#result) of the other subprocesses that were [piped](#pipe-multiple-subprocesses) into this subprocess.724-725-This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.726-727-[More info.](docs/pipe.md#errors)728-729-#### result.command730-731-Type: `string`732-733-The file and [arguments](docs/input.md#command-arguments) that were run.734-735-[More info.](docs/debugging.md#command)736-737-#### result.escapedCommand738-739-Type: `string`740-741-Same as [`command`](#resultcommand) but escaped.742-743-[More info.](docs/debugging.md#command)744-745-#### result.cwd746-747-Type: `string`748-749-The [current directory](#optionscwd) in which the command was run.750-751-[More info.](docs/environment.md#current-directory)752-753-#### result.durationMs754-755-Type: `number`756-757-Duration of the subprocess, in milliseconds.758-759-[More info.](docs/debugging.md#duration)760-761-#### result.failed762-763-Type: `boolean`764-765-Whether the subprocess failed to run.766-767-[More info.](docs/errors.md#subprocess-failure)768-769-#### result.timedOut770-771-Type: `boolean`772-773-Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.774-775-[More info.](docs/termination.md#timeout)776-777-#### result.isCanceled778-779-Type: `boolean`780-781-Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.782-783-[More info.](docs/termination.md#canceling)784-785-#### result.isMaxBuffer786-787-Type: `boolean`788-789-Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.790-791-[More info.](docs/output.md#big-output)792-793-#### result.isTerminated794-795-Type: `boolean`796-797-Whether the subprocess was terminated by a [signal](docs/termination.md#signal-termination) (like [`SIGTERM`](docs/termination.md#sigterm)) sent by either:798-- The current process.799-- [Another process](docs/termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).800-801-[More info.](docs/termination.md#signal-name-and-description)802-803-#### result.exitCode804-805-Type: `number | undefined`806-807-The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.808-809-This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).810-811-[More info.](docs/errors.md#exit-code)812-813-#### result.signal814-815-Type: `string | undefined`816-817-The name of the [signal](docs/termination.md#signal-termination) (like [`SIGTERM`](docs/termination.md#sigterm)) that terminated the subprocess, sent by either:818-- The current process.819-- [Another process](docs/termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).820-821-If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.822-823-[More info.](docs/termination.md#signal-name-and-description)824-825-#### result.signalDescription826-827-Type: `string | undefined`828-829-A human-friendly description of the [signal](docs/termination.md#signal-termination) that was used to terminate the subprocess.830-831-If 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.832-833-[More info.](docs/termination.md#signal-name-and-description)834-835-### ExecaError836-### ExecaSyncError837-838-Type: `Error`839-840-Exception thrown when the subprocess [fails](docs/errors.md#subprocess-failure).841-842-This has the same shape as [successful results](#result), with the following additional properties.843-844-[More info.](docs/errors.md)845-846-#### error.message847-848-Type: `string`849-850-Error message when the subprocess [failed](docs/errors.md#subprocess-failure) to run.851-852-[More info.](docs/errors.md#error-message)853-854-#### error.shortMessage855-856-Type: `string`857-858-This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](docs/output.md).859-860-[More info.](docs/errors.md#error-message)861-862-#### error.originalMessage863-864-Type: `string | undefined`865-866-Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](docs/output.md) and some additional information added by Execa.867-868-[More info.](docs/errors.md#error-message)869-870-#### error.cause871-872-Type: `unknown | undefined`873-874-Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).875-876-This is usually an `Error` instance.877-878-[More info.](docs/termination.md#error-message-and-stack-trace)879-880-#### error.code881-882-Type: `string | undefined`883-884-Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.885-886-### Options887-888-Type: `object`889-890-This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).891-892-The following options [can specify different values](docs/output.md#stdoutstderr-specific-options) for [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr): [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`buffer`](#optionsbuffer), [`maxBuffer`](#optionsmaxbuffer).893-894-#### options.preferLocal895-896-Type: `boolean`\897-Default: `true` with [`$`](#file-arguments-options), `false` otherwise898-899-Prefer locally installed binaries when looking for a binary to execute.900-901-[More info.](docs/environment.md#local-binaries)902-903-#### options.localDir904-905-Type: `string | URL`\906-Default: [`cwd`](#optionscwd) option907-908-Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.909-910-[More info.](docs/environment.md#local-binaries)911-912-#### options.node913-914-Type: `boolean`\915-Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise916-917-If `true`, runs with Node.js. The first argument must be a Node.js file.918-919-[More info.](docs/node.md)920-921-#### options.nodeOptions922-923-Type: `string[]`\924-Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)925-926-List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).927-928-Requires the [`node`](#optionsnode) option to be `true`.929-930-[More info.](docs/node.md#nodejs-cli-flags)931-932-#### options.nodePath933-934-Type: `string | URL`\935-Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)936-937-Path to the Node.js executable.938-939-Requires the [`node`](#optionsnode) option to be `true`.940-941-[More info.](docs/node.md#nodejs-version)942-943-#### options.shell944-945-Type: `boolean | string | URL`\946-Default: `false`947-948-If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).949-950-Uses [`/bin/sh`](https://en.wikipedia.org/wiki/Unix_shell) on UNIX and [`cmd.exe`](https://en.wikipedia.org/wiki/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.951-952-We [recommend against](docs/shell.md#avoiding-shells) using this option.953-954-[More info.](docs/shell.md)955-956-#### options.cwd957-958-Type: `string | URL`\959-Default: `process.cwd()`960-961-Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.962-963-This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.964-965-[More info.](docs/environment.md#current-directory)966-967-#### options.env968-969-Type: `object`\970-Default: [`process.env`](https://nodejs.org/api/process.html#processenv)971-972-[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).973-974-Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).975-976-[More info.](docs/input.md#environment-variables)977-978-#### options.extendEnv979-980-Type: `boolean`\981-Default: `true`982-983-If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).984-If `false`, only the `env` option is used, not `process.env`.985-986-[More info.](docs/input.md#environment-variables)987-988-#### options.input989-990-Type: `string | Uint8Array | stream.Readable`991-992-Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).993-994-See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.995-996-[More info.](docs/input.md#string-input)997-998-#### options.inputFile999-1000-Type: `string | URL`1001-1002-Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).1003-1004-See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.1005-1006-[More info.](docs/input.md#file-input)1007-1008-#### options.stdin1009-1010-Type: `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)\1011-Default: `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise1012-1013-How to setup the subprocess' [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/streams.md#manual-streaming), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/input.md#ignore-input), [`'inherit'`](docs/input.md#terminal-input), a [file descriptor integer](docs/input.md#terminal-input), a [Node.js `Readable` stream](docs/streams.md#input), a web [`ReadableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/input.md#file-input), a [file URL](docs/input.md#file-input), an [`Iterable`](docs/streams.md#iterables-as-input) (including an [array of strings](docs/input.md#string-input)), an [`AsyncIterable`](docs/streams.md#iterables-as-input), an [`Uint8Array`](docs/binary.md#binary-input), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).1014-1015-This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.1016-1017-More info on [available values](docs/input.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).1018-1019-#### options.stdout1020-1021-Type: `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)\1022-Default: `pipe`1023-1024-How to setup the subprocess' [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/output.md#stdout-and-stderr), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/output.md#ignore-output), [`'inherit'`](docs/output.md#terminal-output), a [file descriptor integer](docs/output.md#terminal-output), a [Node.js `Writable` stream](docs/streams.md#output), a web [`WritableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/output.md#file-output), a [file URL](docs/output.md#file-output), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).1025-1026-This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.1027-1028-More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).1029-1030-#### options.stderr1031-1032-Type: `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)\1033-Default: `pipe`1034-1035-How to setup the subprocess' [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/output.md#stdout-and-stderr), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/output.md#ignore-output), [`'inherit'`](docs/output.md#terminal-output), a [file descriptor integer](docs/output.md#terminal-output), a [Node.js `Writable` stream](docs/streams.md#output), a web [`WritableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/output.md#file-output), a [file URL](docs/output.md#file-output), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).1036-1037-This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.1038-1039-More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).1040-1041-#### options.stdio1042-1043-Type: `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)\1044-Default: `pipe`1045-1046-Like the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options but for all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.1047-1048-A single string can be used [as a shortcut](docs/output.md#shortcut).1049-1050-The array can have more than 3 items, to create [additional file descriptors](docs/output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).1051-1052-More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).1053-1054-#### options.all1055-1056-Type: `boolean`\1057-Default: `false`1058-1059-Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.1060-1061-[More info.](docs/output.md#interleaved-output)1062-1063-#### options.encoding1064-1065-Type: `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\1066-Default: `'utf8'`1067-1068-If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).1069-1070-If it outputs binary data instead, this should be either:1071-- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).1072-- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'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.1073-1074-The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).1075-1076-[More info.](docs/binary.md)1077-1078-#### options.lines1079-1080-Type: `boolean`\1081-Default: `false`1082-1083-Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.1084-1085-This cannot be used if the [`encoding`](#optionsencoding) option is [binary](docs/binary.md#binary-output).1086-1087-By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).1088-1089-[More info.](docs/lines.md#simple-splitting)1090-1091-#### options.stripFinalNewline1092-1093-Type: `boolean`\1094-Default: `true`1095-1096-Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.1097-1098-If the [`lines`](#optionslines) option is true, this applies to each output line instead.1099-1100-By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).1101-1102-[More info.](docs/lines.md#newlines)1103-1104-#### options.maxBuffer1105-1106-Type: `number`\1107-Default: `100_000_000`1108-1109-Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).1110-1111-By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).1112-1113-[More info.](docs/output.md#big-output)1114-1115-#### options.buffer1116-1117-Type: `boolean`\1118-Default: `true`1119-1120-When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.1121-1122-By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).1123-1124-[More info.](docs/output.md#low-memory)1125-1126-#### options.ipc1127-1128-Type: `boolean`\1129-Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise1130-1131-Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).1132-1133-[More info.](docs/ipc.md)1134-1135-#### options.serialization1136-1137-Type: `'json' | 'advanced'`\1138-Default: `'advanced'`1139-1140-Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.1141-1142-[More info.](docs/ipc.md#message-type)1143-1144-#### options.verbose1145-1146-Type: `'none' | 'short' | 'full'`\1147-Default: `'none'`1148-1149-If `verbose` is `'short'`, prints the command on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)): its file, arguments, duration and (if it failed) error message.1150-1151-If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.1152-1153-By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).1154-1155-[More info.](docs/debugging.md#verbose-mode)1156-1157-#### options.reject1158-1159-Type: `boolean`\1160-Default: `true`1161-1162-Setting this to `false` resolves the [result's promise](#subprocess) with the [error](#execaerror) instead of rejecting it.1163-1164-[More info.](docs/errors.md#preventing-exceptions)1165-1166-#### options.timeout1167-1168-Type: `number`\1169-Default: `0`1170-1171-If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.1172-1173-On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.1174-1175-[More info.](docs/termination.md#timeout)1176-1177-#### options.cancelSignal1178-1179-Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)1180-1181-You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).1182-1183-When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.1184-1185-[More info.](docs/termination.md#canceling)1186-1187-#### options.forceKillAfterDelay1188-1189-Type: `number | false`\1190-Default: `5000`1191-1192-If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).1193-1194-[More info.](docs/termination.md#forceful-termination)1195-1196-#### options.killSignal1197-1198-Type: `string | number`\1199-Default: `'SIGTERM'`1200-1201-Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.1202-1203-This can be either a name (like [`'SIGTERM'`](docs/termination.md#sigterm)) or a number (like `9`).1204-1205-[More info.](docs/termination.md#default-signal)1206-1207-#### options.detached1208-1209-Type: `boolean`\1210-Default: `false`1211-1212-Run the subprocess independently from the current process.1213-1214-[More info.](docs/environment.md#background-subprocess)1215-1216-#### options.cleanup1217-1218-Type: `boolean`\1219-Default: `true`1220-1221-Kill the subprocess when the current process exits.1222-1223-[More info.](docs/termination.md#current-process-exit)1224-1225-#### options.uid1226-1227-Type: `number`\1228-Default: current user identifier1229-1230-Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.1231-1232-[More info.](docs/windows.md#uid-and-gid)1233-1234-#### options.gid1235-1236-Type: `number`\1237-Default: current group identifier1238-1239-Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.1240-1241-[More info.](docs/windows.md#uid-and-gid)1242-1243-#### options.argv01244-1245-Type: `string`\1246-Default: file being executed1247-1248-Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.1249-1250-#### options.windowsHide1251-1252-Type: `boolean`\1253-Default: `true`1254-1255-On Windows, do not create a new console window.1256-1257-[More info.](docs/windows.md#console-window)1258-1259-#### options.windowsVerbatimArguments1260-1261-Type: `boolean`\1262-Default: `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise1263-1264-If `false`, escapes the command arguments on Windows.1265-1266-[More info.](docs/windows.md#cmdexe-escaping)1267-1268-### Transform options1269-1270-A transform or an [array of transforms](docs/transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.1271-1272-A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.1273-1274-[More info.](docs/transform.md)1275-1276-#### transformOptions.transform1277-1278-Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`1279-1280-Map or [filter](docs/transform.md#filtering) the [input](docs/input.md) or [output](docs/output.md) of the subprocess.1281-1282-More info [here](docs/transform.md#summary) and [there](docs/transform.md#sharing-state).1283-1284-#### transformOptions.final1285-1286-Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`1287-1288-Create additional lines after the last one.1289-1290-[More info.](docs/transform.md#finalizing)1291-1292-#### transformOptions.binary1293-1294-Type: `boolean`\1295-Default: `false`1296-1297-If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.1298-1299-[More info.](docs/binary.md#transforms)1300-1301-#### transformOptions.preserveNewlines1302-1303-Type: `boolean`\1304-Default: `false`1305-1306-If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.1307-1308-[More info.](docs/lines.md#transforms)1309-1310-#### transformOptions.objectMode1311-1312-Type: `boolean`\1313-Default: `false`1314-1315-If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.1316-1317-[More info.](docs/transform.md#object-mode)1318-303 ## Related304 305 - [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa306 - [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version5 unmodified lines