api.md
This file
Path
docs/api.md
1,043 lines · 40.9 KiB · Markdown
Last changed by
Rename some types (#1009)ehmickybefore adoption2ef9186
History of this fileTake it
Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1–17why, one step back1<picture>2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 📔 API reference89This 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.1011## Methods1213### execa(file, arguments?, options?)1415`file`: `string | URL`\16`arguments`: `string[]`\17`options`: [`Options`](#options)\Rename some types (#1009)ehmickybefore adoption2ef9186
line 18why, one step back18_Returns_: [`ResultPromise`](#return-value)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 19–28why, one step back1920Executes a command using `file ...arguments`.2122More info on the [syntax](execution.md#array-syntax) and [escaping](escaping.md#array-syntax).2324### execa\`command\`25### execa(options)\`command\`2627`command`: `string`\28`options`: [`Options`](#options)\Rename some types (#1009)ehmickybefore adoption2ef9186
line 29why, one step back29_Returns_: [`ResultPromise`](#return-value)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 30–46why, one step back3031Executes a command. `command` is a [template string](execution.md#template-string-syntax) that includes both the `file` and its `arguments`.3233More info on the [syntax](execution.md#template-string-syntax) and [escaping](escaping.md#template-string-syntax).3435### execa(options)3637`options`: [`Options`](#options)\38_Returns_: [`execa`](#execafile-arguments-options)3940Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.4142[More info.](execution.md#globalshared-options)4344### execaSync(file, arguments?, options?)45### execaSync\`command\`46Rename some types (#1009)ehmickybefore adoption2ef9186
line 47why, one step back47_Returns_: [`SyncResult`](#return-value)Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 48why, one step back48Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 49–59why, one step back49Same as [`execa()`](#execafile-arguments-options) but synchronous.5051Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.5253[More info.](execution.md#synchronous-execution)5455### $(file, arguments?, options?)5657`file`: `string | URL`\58`arguments`: `string[]`\59`options`: [`Options`](#options)\Rename some types (#1009)ehmickybefore adoption2ef9186
line 60why, one step back60_Returns_: [`ResultPromise`](#return-value)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 61–74why, one step back6162Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](scripts.md#script-files).6364Just 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()`.6566This is the preferred method when executing multiple commands in a script file.6768[More info.](scripts.md)6970### execaNode(scriptPath, arguments?, options?)7172`scriptPath`: `string | URL`\73`arguments`: `string[]`\74`options`: [`Options`](#options)\Rename some types (#1009)ehmickybefore adoption2ef9186
line 75why, one step back75_Returns_: [`ResultPromise`](#return-value)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 76–89why, one step back7677Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.78Executes a Node.js file using `node scriptPath ...arguments`.7980Just like `execa()`, this can use the [template string syntax](execution.md#template-string-syntax) or [bind options](execution.md#globalshared-options).8182This is the preferred method when executing Node.js files.8384[More info.](node.md)8586### execaCommand(command, options?)8788`command`: `string`\89`options`: [`Options`](#options)\Rename some types (#1009)ehmickybefore adoption2ef9186
line 90why, one step back90_Returns_: [`ResultPromise`](#return-value)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 91–99why, one step back9192Executes a command. `command` is a string that includes both the `file` and its `arguments`.9394This 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.9596Just like `execa()`, this can [bind options](execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.9798[More info.](escaping.md#user-defined-input)99Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 100why, one step back100## Return valueMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 101why, one step back101Rename some types (#1009)ehmickybefore adoption2ef9186
line 102why, one step back102_Type_: `ResultPromise`Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 103why, one step back103Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 104why, one step back104The return value of all [asynchronous methods](#methods) is both:Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 105–106why, one step back105- the [subprocess](#subprocess).106- a `Promise` either resolving with its successful [`result`](#result), or rejecting with its [`error`](#execaerror).Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 107–109why, one step back107108[More info.](execution.md#subprocess)109Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 110–111why, one step back110## Subprocess111Rename some types (#1009)ehmickybefore adoption2ef9186
line 112why, one step back112_Type_: `Subprocess`Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 113–115why, one step back113114[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.115Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 116–158why, one step back116### subprocess\[Symbol.asyncIterator\]()117118_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)119120Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.121122[More info.](lines.md#progressive-splitting)123124### subprocess.iterable(readableOptions?)125126`readableOptions`: [`ReadableOptions`](#readableoptions)\127_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)128129Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.130131[More info.](lines.md#progressive-splitting)132133### subprocess.pipe(file, arguments?, options?)134135`file`: `string | URL`\136`arguments`: `string[]`\137`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\138_Returns_: [`Promise<Result>`](#result)139140[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.141142This 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.143144[More info.](pipe.md#array-syntax)145146### subprocess.pipe\`command\`147### subprocess.pipe(options)\`command\`148149`command`: `string`\150`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\151_Returns_: [`Promise<Result>`](#result)152153Like [`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).154155[More info.](pipe.md#template-string-syntax)156157### subprocess.pipe(secondSubprocess, pipeOptions?)158Rename some types (#1009)ehmickybefore adoption2ef9186
line 159why, one step back159`secondSubprocess`: [`ResultPromise`](#return-value)\Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 160–162why, one step back160`pipeOptions`: [`PipeOptions`](#pipeoptions)\161_Returns_: [`Promise<Result>`](#result)162Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 163why, one step back163Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#return-value) of another [`execa()`](#execafile-arguments-options) call instead.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 164–205why, one step back164165[More info.](pipe.md#advanced-syntax)166167#### pipeOptions168169Type: `object`170171#### pipeOptions.from172173Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\174Default: `"stdout"`175176Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.177178`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.179180[More info.](pipe.md#source-file-descriptor)181182#### pipeOptions.to183184Type: `"stdin" | "fd3" | "fd4" | ...`\185Default: `"stdin"`186187Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.188189[More info.](pipe.md#destination-file-descriptor)190191#### pipeOptions.unpipeSignal192193Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)194195Unpipe the subprocess when the signal aborts.196197[More info.](pipe.md#unpipe)198199### subprocess.kill(signal, error?)200### subprocess.kill(error?)201202`signal`: `string | number`\203`error`: `Error`\204_Returns_: `boolean`205Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 206why, one step back206Sends 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](#erroristerminated) the subprocess.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 207–381why, one step back207208This returns `false` when the signal could not be sent, for example when the subprocess has already exited.209210When 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).211212[More info.](termination.md)213214### subprocess.pid215216_Type_: `number | undefined`217218Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).219220This is `undefined` if the subprocess failed to spawn.221222[More info.](termination.md#inter-process-termination)223224### subprocess.send(message)225226`message`: `unknown`\227_Returns_: `boolean`228229Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.230The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).231232This returns `true` on success.233234This requires the [`ipc`](#optionsipc) option to be `true`.235236[More info.](ipc.md#exchanging-messages)237238### subprocess.on('message', (message) => void)239240`message`: `unknown`241242Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.243The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).244245This requires the [`ipc`](#optionsipc) option to be `true`.246247[More info.](ipc.md#exchanging-messages)248249### subprocess.stdin250251Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)252253The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.254255This 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).256257[More info.](streams.md#manual-streaming)258259### subprocess.stdout260261Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)262263The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.264265This 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`.266267[More info.](streams.md#manual-streaming)268269### subprocess.stderr270271Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)272273The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.274275This 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`.276277[More info.](streams.md#manual-streaming)278279### subprocess.all280281Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)282283Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).284285This requires the [`all`](#optionsall) option to be `true`.286287This 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`.288289More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).290291### subprocess.stdio292293Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)294295The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.296297Each 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`.298299[More info.](streams.md#manual-streaming)300301### subprocess.readable(readableOptions?)302303`readableOptions`: [`ReadableOptions`](#readableoptions)\304_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream305306Converts the subprocess to a readable stream.307308[More info.](streams.md#converting-a-subprocess-to-a-stream)309310#### readableOptions311312Type: `object`313314#### readableOptions.from315316Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\317Default: `"stdout"`318319Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.320321`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.322323[More info.](streams.md#different-file-descriptor)324325#### readableOptions.binary326327Type: `boolean`\328Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)329330If `false`, iterates over lines. Each line is a string.331332If `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)).333334This is always `true` when the [`encoding`](#optionsencoding) option is binary.335336More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).337338#### readableOptions.preserveNewlines339340Type: `boolean`\341Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)342343If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.344345[More info.](lines.md#iterable)346347### subprocess.writable(writableOptions?)348349`writableOptions`: [`WritableOptions`](#writableoptions)\350_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream351352Converts the subprocess to a writable stream.353354[More info.](streams.md#converting-a-subprocess-to-a-stream)355356#### writableOptions357358Type: `object`359360#### writableOptions.to361362Type: `"stdin" | "fd3" | "fd4" | ...`\363Default: `"stdin"`364365Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.366367[More info.](streams.md#different-file-descriptor)368369### subprocess.duplex(duplexOptions?)370371`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\372_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream373374Converts the subprocess to a duplex stream.375376[More info.](streams.md#converting-a-subprocess-to-a-stream)377378## Result379380Type: `object`381Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 382why, one step back382[Result](execution.md#result) of a subprocess successful execution.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 383–483why, one step back383384When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.385386### result.stdout387388Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`389390The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).391392This 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`.393394This 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).395396[More info.](output.md#stdout-and-stderr)397398### result.stderr399400Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`401402The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).403404This 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`.405406This 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).407408[More info.](output.md#stdout-and-stderr)409410### result.all411412Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`413414The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.415416This requires the [`all`](#optionsall) option to be `true`.417418This 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`.419420This 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).421422[More info.](output.md#interleaved-output)423424### result.stdio425426Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`427428The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).429430Items 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`.431432Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).433434[More info.](output.md#additional-file-descriptors)435436### result.pipedFrom437438Type: [`Array<Result | ExecaError>`](#result)439440[Results](#result) of the other subprocesses that were piped into this subprocess.441442This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.443444[More info.](pipe.md#result)445446### result.command447448Type: `string`449450The file and [arguments](input.md#command-arguments) that were run.451452[More info.](debugging.md#command)453454### result.escapedCommand455456Type: `string`457458Same as [`command`](#resultcommand) but escaped.459460[More info.](debugging.md#command)461462### result.cwd463464Type: `string`465466The [current directory](#optionscwd) in which the command was run.467468[More info.](environment.md#current-directory)469470### result.durationMs471472Type: `number`473474Duration of the subprocess, in milliseconds.475476[More info.](debugging.md#duration)477478### result.failed479480Type: `boolean`481482Whether the subprocess failed to run.483Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 484–485why, one step back484When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.485Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 486–487why, one step back486[More info.](errors.md#subprocess-failure)487Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 488–489why, one step back488## ExecaError489## ExecaSyncErrorMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 490why, one step back490Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 491–542why, one step back491Type: `Error`492493Result of a subprocess [failed execution](errors.md#subprocess-failure).494495This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.496497This has the same shape as [successful results](#result), with the following additional properties.498499[More info.](errors.md)500501### error.message502503Type: `string`504505Error message when the subprocess [failed](errors.md#subprocess-failure) to run.506507[More info.](errors.md#error-message)508509### error.shortMessage510511Type: `string`512513This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).514515[More info.](errors.md#error-message)516517### error.originalMessage518519Type: `string | undefined`520521Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.522523[More info.](errors.md#error-message)524525### error.cause526527Type: `unknown | undefined`528529Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).530531This is usually an `Error` instance.532533[More info.](termination.md#error-message-and-stack-trace)534535### error.code536537Type: `string | undefined`538539Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.540541### error.timedOut542Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 543–548why, one step back543Type: `boolean`544545Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.546547[More info.](termination.md#timeout)548Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 549why, one step back549### error.isCanceledMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 550–556why, one step back550551Type: `boolean`552553Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.554555[More info.](termination.md#canceling)556Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 557why, one step back557### error.isMaxBufferMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 558–564why, one step back558559Type: `boolean`560561Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.562563[More info.](output.md#big-output)564Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 565why, one step back565### error.isTerminatedMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 566–574why, one step back566567Type: `boolean`568569Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:570- The current process.571- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).572573[More info.](termination.md#signal-name-and-description)574Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 575why, one step back575### error.exitCodeMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 576–580why, one step back576577Type: `number | undefined`578579The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.580Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 581why, one step back581This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#errorsignal).Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 582–584why, one step back582583[More info.](errors.md#exit-code)584Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 585why, one step back585### error.signalMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 586–596why, one step back586587Type: `string | undefined`588589The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:590- The current process.591- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).592593If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.594595[More info.](termination.md#signal-name-and-description)596Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 597why, one step back597### error.signalDescriptionMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 598–882why, one step back598599Type: `string | undefined`600601A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.602603If 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.604605[More info.](termination.md#signal-name-and-description)606607## Options608609Type: `object`610611This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).612613The 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).614615### options.preferLocal616617Type: `boolean`\618Default: `true` with [`$`](#file-arguments-options), `false` otherwise619620Prefer locally installed binaries when looking for a binary to execute.621622[More info.](environment.md#local-binaries)623624### options.localDir625626Type: `string | URL`\627Default: [`cwd`](#optionscwd) option628629Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.630631[More info.](environment.md#local-binaries)632633### options.node634635Type: `boolean`\636Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise637638If `true`, runs with Node.js. The first argument must be a Node.js file.639640[More info.](node.md)641642### options.nodeOptions643644Type: `string[]`\645Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)646647List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).648649Requires the [`node`](#optionsnode) option to be `true`.650651[More info.](node.md#nodejs-cli-flags)652653### options.nodePath654655Type: `string | URL`\656Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)657658Path to the Node.js executable.659660Requires the [`node`](#optionsnode) option to be `true`.661662[More info.](node.md#nodejs-version)663664### options.shell665666Type: `boolean | string | URL`\667Default: `false`668669If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).670671Uses [`/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.672673We [recommend against](shell.md#avoiding-shells) using this option.674675[More info.](shell.md)676677### options.cwd678679Type: `string | URL`\680Default: `process.cwd()`681682Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.683684This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.685686[More info.](environment.md#current-directory)687688### options.env689690Type: `object`\691Default: [`process.env`](https://nodejs.org/api/process.html#processenv)692693[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).694695Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).696697[More info.](input.md#environment-variables)698699### options.extendEnv700701Type: `boolean`\702Default: `true`703704If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).705If `false`, only the `env` option is used, not `process.env`.706707[More info.](input.md#environment-variables)708709### options.input710711Type: `string | Uint8Array | stream.Readable`712713Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).714715See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.716717[More info.](input.md#string-input)718719### options.inputFile720721Type: `string | URL`722723Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).724725See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.726727[More info.](input.md#file-input)728729### options.stdin730731Type: `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)\732Default: `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise733734How 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).735736This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.737738More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).739740### options.stdout741742Type: `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)\743Default: `pipe`744745How 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).746747This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.748749More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).750751### options.stderr752753Type: `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)\754Default: `pipe`755756How 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).757758This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.759760More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).761762### options.stdio763764Type: `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)\765Default: `pipe`766767Like 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'}`.768769A single string can be used [as a shortcut](output.md#shortcut).770771The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).772773More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).774775### options.all776777Type: `boolean`\778Default: `false`779780Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.781782[More info.](output.md#interleaved-output)783784### options.encoding785786Type: `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\787Default: `'utf8'`788789If 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).790791If it outputs binary data instead, this should be either:792- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).793- [`'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.794795The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).796797[More info.](binary.md)798799### options.lines800801Type: `boolean`\802Default: `false`803804Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.805806This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).807808By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).809810[More info.](lines.md#simple-splitting)811812### options.stripFinalNewline813814Type: `boolean`\815Default: `true`816817Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.818819If the [`lines`](#optionslines) option is true, this applies to each output line instead.820821By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).822823[More info.](lines.md#newlines)824825### options.maxBuffer826827Type: `number`\828Default: `100_000_000`829830Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).831832By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).833834[More info.](output.md#big-output)835836### options.buffer837838Type: `boolean`\839Default: `true`840841When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.842843By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).844845[More info.](output.md#low-memory)846847### options.ipc848849Type: `boolean`\850Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise851852Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).853854[More info.](ipc.md)855856### options.serialization857858Type: `'json' | 'advanced'`\859Default: `'advanced'`860861Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.862863[More info.](ipc.md#message-type)864865### options.verbose866867Type: `'none' | 'short' | 'full'`\868Default: `'none'`869870If `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.871872If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.873874By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).875876[More info.](debugging.md#verbose-mode)877878### options.reject879880Type: `boolean`\881Default: `true`882Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 883why, one step back883Setting this to `false` resolves the [result's promise](#return-value) with the [error](#execaerror) instead of rejecting it.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 884–893why, one step back884885[More info.](errors.md#preventing-exceptions)886887### options.timeout888889Type: `number`\890Default: `0`891892If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.893Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 894why, one step back894On timeout, [`result.timedOut`](#errortimedout) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 895–903why, one step back895896[More info.](termination.md#timeout)897898### options.cancelSignal899900Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)901902You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).903Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 904why, one step back904When `AbortController.abort()` is called, [`result.isCanceled`](#erroriscanceled) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 905–1043why, one step back905906[More info.](termination.md#canceling)907908### options.forceKillAfterDelay909910Type: `number | false`\911Default: `5000`912913If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).914915[More info.](termination.md#forceful-termination)916917### options.killSignal918919Type: `string | number`\920Default: `'SIGTERM'`921922Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.923924This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).925926[More info.](termination.md#default-signal)927928### options.detached929930Type: `boolean`\931Default: `false`932933Run the subprocess independently from the current process.934935[More info.](environment.md#background-subprocess)936937### options.cleanup938939Type: `boolean`\940Default: `true`941942Kill the subprocess when the current process exits.943944[More info.](termination.md#current-process-exit)945946### options.uid947948Type: `number`\949Default: current user identifier950951Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.952953[More info.](windows.md#uid-and-gid)954955### options.gid956957Type: `number`\958Default: current group identifier959960Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.961962[More info.](windows.md#uid-and-gid)963964### options.argv0965966Type: `string`\967Default: file being executed968969Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.970971### options.windowsHide972973Type: `boolean`\974Default: `true`975976On Windows, do not create a new console window.977978[More info.](windows.md#console-window)979980### options.windowsVerbatimArguments981982Type: `boolean`\983Default: `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise984985If `false`, escapes the command arguments on Windows.986987[More info.](windows.md#cmdexe-escaping)988989## Transform options990991A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.992993A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.994995[More info.](transform.md)996997### transformOptions.transform998999Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`10001001Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.10021003More info [here](transform.md#summary) and [there](transform.md#sharing-state).10041005### transformOptions.final10061007Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`10081009Create additional lines after the last one.10101011[More info.](transform.md#finalizing)10121013### transformOptions.binary10141015Type: `boolean`\1016Default: `false`10171018If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.10191020[More info.](binary.md#transforms)10211022### transformOptions.preserveNewlines10231024Type: `boolean`\1025Default: `false`10261027If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.10281029[More info.](lines.md#transforms)10301031### transformOptions.objectMode10321033Type: `boolean`\1034Default: `false`10351036If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.10371038[More info.](transform.md#object-mode)10391040<hr>10411042[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1043[**Top**: Table of contents](../readme.md#documentation)