Skip to content
Myr

api.md

This file

Path

docs/api.md

1,371 lines · 55.1 KiB · Markdown

Last changed by

Fix `escapedCommand` and `verbose` quoting arguments when using the `shell` optionSindre Sorhusbefore adoptionb2c3a54

History of this file

Take it

Show it rendered

1<picture>2       <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3       <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 📔 API reference89This lists all available [methods](#methods) and their [options](#options-1). 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-1)\18_Returns_: [`ResultPromise`](#return-value)1920Executes a command using `file ...arguments`.2122More info on the [syntax](execution.md#array-syntax) and [escaping](escaping.md#array-syntax).2324### $(file, arguments?, options?)2526`file`: `string | URL`\27`arguments`: `string[]`\28`options`: [`Options`](#options-1)\29_Returns_: [`ResultPromise`](#return-value)3031Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](scripts.md#script-files).3233This is the preferred method when executing multiple commands in a script file.3435[More info.](scripts.md)3637### execaNode(scriptPath, arguments?, options?)3839`scriptPath`: `string | URL`\40`arguments`: `string[]`\41`options`: [`Options`](#options-1)\42_Returns_: [`ResultPromise`](#return-value)4344Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.45Executes a Node.js file using `node scriptPath ...arguments`.4647This is the preferred method when executing Node.js files.4849[More info.](node.md)5051### execaSync(file, arguments?, options?)52### $.sync(file, arguments?, options?)53### $.s(file, arguments?, options?)5455`file`: `string | URL`\56`arguments`: `string[]`\57`options`: [`SyncOptions`](#options-1)\58_Returns_: [`SyncResult`](#return-value)5960Same as [`execa()`](#execafile-arguments-options) and [`$`](#file-arguments-options) but synchronous.6162Returns a subprocess [`result`](#result) or throws an [`error`](#execasyncerror). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.6364Those methods are discouraged as they hold the CPU and lack multiple features.6566[More info.](execution.md#synchronous-execution)6768### execa\`command\`69### $\`command\`70### execaNode\`command\`71### execaSync\`command\`72### $.sync\`command\`73### $.s\`command\`7475`command`: `string`\76_Returns_: [`ResultPromise`](#return-value), [`SyncResult`](#return-value)7778Same as [`execa()`](#execafile-arguments-options), [`$()`](#file-arguments-options), [`execaNode()`](#execanodescriptpath-arguments-options) and [`execaSync()`](#execasyncfile-arguments-options) but using a [template string](execution.md#template-string-syntax). `command` includes both the `file` and its `arguments`.7980More info on the [syntax](execution.md#template-string-syntax) and [escaping](escaping.md#template-string-syntax).8182### execa(options)\`command\`83### $(options)\`command\`84### execaNode(options)\`command\`85### execaSync(options)\`command\`86### $.sync(options)\`command\`87### $.s(options)\`command\`8889`command`: `string`\90`options`: [`Options`](#options-1), [`SyncOptions`](#options-1)\91_Returns_: [`ResultPromise`](#return-value), [`SyncResult`](#return-value)9293Same as [```execa`command` ```](#execacommand) but with [options](#options-1).9495[More info.](execution.md#template-string-syntax)9697### execa(options)98### $(options)99### execaNode(options)100### execaSync(options)101### $.sync(options)102### $.s(options)103104`options`: [`Options`](#options-1), [`SyncOptions`](#options-1)\105_Returns_: [`ExecaMethod`](#execafile-arguments-options), [`ExecaScriptMethod`](#file-arguments-options), [`ExecaNodeMethod`](#execanodescriptpath-arguments-options), [`ExecaSyncMethod`](#execasyncfile-arguments-options), [`ExecaScriptSyncMethod`](#syncfile-arguments-options)106107Returns a new instance of those methods but with different default [`options`](#options-1). Consecutive calls are merged to previous ones.108109[More info.](execution.md#globalshared-options)110111### parseCommandString(command)112113`command`: `string`\114_Returns_: `string[]`115116Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`.117118[More info.](escaping.md#user-defined-input)119120### sendMessage(message, sendMessageOptions?)121122`message`: [`Message`](ipc.md#message-type)\123`sendMessageOptions`: [`SendMessageOptions`](#sendmessageoptions)\124_Returns_: `Promise<void>`125126Send a `message` to the parent process.127128This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.129130[More info.](ipc.md#exchanging-messages)131132#### sendMessageOptions133134_Type_: `object`135136#### sendMessageOptions.strict137138_Type_: `boolean`\139_Default_: `false`140141Throw when the other process is not receiving or listening to messages.142143[More info.](ipc.md#ensure-messages-are-received)144145### getOneMessage(getOneMessageOptions?)146147`getOneMessageOptions`: [`GetOneMessageOptions`](#getonemessageoptions)\148_Returns_: [`Promise<Message>`](ipc.md#message-type)149150Receive a single `message` from the parent process.151152This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.153154[More info.](ipc.md#exchanging-messages)155156#### getOneMessageOptions157158_Type_: `object`159160#### getOneMessageOptions.filter161162_Type_: [`(Message) => boolean`](ipc.md#message-type)163164Ignore any `message` that returns `false`.165166[More info.](ipc.md#filter-messages)167168#### getOneMessageOptions.reference169170_Type_: `boolean`\171_Default_: `true`172173Keep the subprocess alive while `getOneMessage()` is waiting.174175[More info.](ipc.md#keeping-the-subprocess-alive)176177### getEachMessage(getEachMessageOptions?)178179`getEachMessageOptions`: [`GetEachMessageOptions`](#geteachmessageoptions)\180_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)181182Iterate over each `message` from the parent process.183184This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.185186[More info.](ipc.md#listening-to-messages)187188#### getEachMessageOptions189190_Type_: `object`191192#### getEachMessageOptions.reference193194_Type_: `boolean`\195_Default_: `true`196197Keep the subprocess alive while `getEachMessage()` is waiting.198199[More info.](ipc.md#keeping-the-subprocess-alive)200201### getCancelSignal()202203_Returns_: [`Promise<AbortSignal>`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)204205Retrieves the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) shared by the [`cancelSignal`](#optionscancelsignal) option.206207This can only be called inside a subprocess. This requires the [`gracefulCancel`](#optionsgracefulcancel) option to be `true`.208209[More info.](termination.md#graceful-termination)210211## Return value212213_TypeScript:_ [`ResultPromise`](typescript.md)\214_Type:_ `Subprocess`215216The return value of all [asynchronous methods](#methods) is both:217- the [subprocess](#subprocess).218- a `Promise` either resolving with its successful [`result`](#result), or rejecting with its [`error`](#execaerror).219220[More info.](execution.md#subprocess)221222## Subprocess223224_TypeScript:_ [`Subprocess`](typescript.md)225226Promise with the following Execa-specific methods and properties.227228The underlying Node.js [`ChildProcess`](https://nodejs.org/api/child_process.html#class-childprocess) instance is available as [`subprocess.nodeChildProcess`](#subprocessnodechildprocess). This is an escape hatch for Node.js-specific APIs that Execa does not document, such as `.on()`, `.send()`, `.disconnect()`, `.ref()` and `.unref()`.229230### subprocess\[Symbol.asyncIterator\]()231232_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)233234Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.235236[More info.](lines.md#progressive-splitting)237238### subprocess.iterable(readableOptions?)239240`readableOptions`: [`ReadableOptions`](#readableoptions)\241_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)242243Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.244245[More info.](lines.md#progressive-splitting)246247### subprocess.pipe(file, arguments?, options?)248249`file`: `string | URL`\250`arguments`: `string[]`\251`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\252_Returns_: [`Promise<Result>`](#result)253254[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.255256This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options-1) and [pipe-specific options](#pipeoptions) can be specified.257258Like a subprocess, the return value can be [iterated](lines.md#progressive-splitting), [converted to a stream](streams.md#converting-a-subprocess-to-a-stream), or used for [IPC](ipc.md) with the destination subprocess.259260[More info.](pipe.md#array-syntax)261262### subprocess.pipe\`command\`263### subprocess.pipe(options)\`command\`264265`command`: `string`\266`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\267_Returns_: [`Promise<Result>`](#result)268269Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](execution.md#template-string-syntax) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).270271[More info.](pipe.md#template-string-syntax)272273### subprocess.pipe(secondSubprocess, pipeOptions?)274275`secondSubprocess`: [`ResultPromise`](#return-value)\276`pipeOptions`: [`PipeOptions`](#pipeoptions)\277_Returns_: [`Promise<Result>`](#result)278279Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#return-value) of another [`execa()`](#execafile-arguments-options) call instead.280281[More info.](pipe.md#advanced-syntax)282283#### pipeOptions284285_Type:_ `object`286287#### pipeOptions.from288289_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\290_Default:_ `"stdout"`291292Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.293294`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.295296[More info.](pipe.md#source-file-descriptor)297298#### pipeOptions.to299300_Type:_ `"stdin" | "fd3" | "fd4" | ...`\301_Default:_ `"stdin"`302303Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.304305[More info.](pipe.md#destination-file-descriptor)306307#### pipeOptions.unpipeSignal308309_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)310311Unpipe the subprocess when the signal aborts.312313[More info.](pipe.md#unpipe)314315### subprocess.kill(signal, error?)316### subprocess.kill(error?)317318`signal`: `string | number`\319`error`: `Error`\320_Returns_: `boolean`321322Sends 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.323324This returns `false` when the signal could not be sent, for example when the subprocess has already exited.325326When 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).327328[More info.](termination.md)329330### subprocess.pid331332_Type:_ `number | undefined`333334Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).335336This is `undefined` if the subprocess failed to spawn.337338[More info.](termination.md#inter-process-termination)339340### subprocess.nodeChildProcess341342_Type:_ [`ChildProcess`](https://nodejs.org/api/child_process.html#class-childprocess)343344Underlying Node.js child process instance.345346This is intended as an escape hatch for Node.js-specific APIs that Execa does not document.347348### subprocess.sendMessage(message, sendMessageOptions)349350`message`: [`Message`](ipc.md#message-type)\351`sendMessageOptions`: [`SendMessageOptions`](#sendmessageoptions)\352_Returns_: `Promise<void>`353354Send a `message` to the subprocess.355356This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.357358[More info.](ipc.md#exchanging-messages)359360### subprocess.getOneMessage(getOneMessageOptions?)361362`getOneMessageOptions`: [`GetOneMessageOptions`](#getonemessageoptions)\363_Returns_: [`Promise<Message>`](ipc.md#message-type)364365Receive a single `message` from the subprocess.366367This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.368369[More info.](ipc.md#exchanging-messages)370371### subprocess.getEachMessage(getEachMessageOptions?)372373`getEachMessageOptions`: [`GetEachMessageOptions`](#geteachmessageoptions)\374_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)375376Iterate over each `message` from the subprocess.377378This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.379380[More info.](ipc.md#listening-to-messages)381382### subprocess.stdin383384_Type:_ [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)385386The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.387388This 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).389390[More info.](streams.md#manual-streaming)391392### subprocess.stdout393394_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)395396The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.397398This 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).399400[More info.](streams.md#manual-streaming)401402### subprocess.stderr403404_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)405406The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.407408This is `null` if the [`stderr`](#optionsstderr) option is set to [`'inherit'`](output.md#terminal-output), [`'ignore'`](output.md#ignore-output), [`Writable`](streams.md#output) or [`integer`](output.md#terminal-output).409410[More info.](streams.md#manual-streaming)411412### subprocess.all413414_Type:_ [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)415416Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).417418This requires the [`all`](#optionsall) option to be `true`.419420This is `undefined` if both [`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).421422More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).423424### subprocess.stdio425426_Type:_ [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)427428The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.429430Each 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).431432With the [`ipc`](#optionsipc) option, the last item is the subprocess' IPC channel, which is always `null`.433434[More info.](streams.md#manual-streaming)435436### subprocess.readable(readableOptions?)437438`readableOptions`: [`ReadableOptions`](#readableoptions)\439_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream440441Converts the subprocess to a readable stream.442443[More info.](streams.md#converting-a-subprocess-to-a-stream)444445#### readableOptions446447_Type:_ `object`448449#### readableOptions.from450451_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\452_Default:_ `"stdout"`453454Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.455456`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.457458[More info.](streams.md#different-file-descriptor)459460#### readableOptions.binary461462_Type:_ `boolean`\463_Default:_ `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)464465If `false`, iterates over lines. Each line is a string.466467If `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)).468469This is always `true` when the [`encoding`](#optionsencoding) option is binary.470471More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).472473#### readableOptions.preserveNewlines474475_Type:_ `boolean`\476_Default:_ `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)477478If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.479480[More info.](lines.md#iterable)481482### subprocess.writable(writableOptions?)483484`writableOptions`: [`WritableOptions`](#writableoptions)\485_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream486487Converts the subprocess to a writable stream.488489[More info.](streams.md#converting-a-subprocess-to-a-stream)490491#### writableOptions492493_Type:_ `object`494495#### writableOptions.to496497_Type:_ `"stdin" | "fd3" | "fd4" | ...`\498_Default:_ `"stdin"`499500Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.501502[More info.](streams.md#different-file-descriptor)503504### subprocess.duplex(duplexOptions?)505506`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\507_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream508509Converts the subprocess to a duplex stream.510511[More info.](streams.md#converting-a-subprocess-to-a-stream)512513### subprocess.readableStream(readableOptions?)514515`readableOptions`: [`ReadableOptions`](#readableoptions)\516_Returns_: [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) web stream517518Converts the subprocess to a readable web stream.519520[More info.](streams.md#converting-a-subprocess-to-a-web-stream)521522### subprocess.writableStream(writableOptions?)523524`writableOptions`: [`WritableOptions`](#writableoptions)\525_Returns_: [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) web stream526527Converts the subprocess to a writable web stream.528529[More info.](streams.md#converting-a-subprocess-to-a-web-stream)530531### subprocess.transformStream(duplexOptions?)532533`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\534_Returns_: [`{readable: ReadableStream, writable: WritableStream}`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream)535536Converts the subprocess to a [`{readable, writable}`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) pair of web streams.537538[More info.](streams.md#converting-a-subprocess-to-a-web-stream)539540## Result541542_TypeScript:_ [`Result`](typescript.md) or [`SyncResult`](typescript.md)\543_Type:_ `object`544545[Result](execution.md#result) of a subprocess successful execution.546547When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.548549### result.stdout550551_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`552553The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).554555This 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`.556557This 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).558559[More info.](output.md#stdout-and-stderr)560561### result.stderr562563_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`564565The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).566567This 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`.568569This 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).570571[More info.](output.md#stdout-and-stderr)572573### result.all574575_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`576577The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.578579This requires the [`all`](#optionsall) option to be `true`.580581This 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` for both.582583This 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).584585[More info.](output.md#interleaved-output)586587### result.stdio588589_Type:_ `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`590591The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).592593Items 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`.594595With the [`ipc`](#optionsipc) option, the last item is the subprocess' IPC channel, which is always `undefined`.596597Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).598599[More info.](output.md#additional-file-descriptors)600601### result.ipcOutput602603_Type_: [`Message[]`](ipc.md#message-type)604605All the messages [sent by the subprocess](#sendmessagemessage-sendmessageoptions) to the current process.606607This is empty unless the [`ipc`](#optionsipc) option is `true`. Also, this is empty if the [`buffer`](#optionsbuffer) option is `false`.608609[More info.](ipc.md#retrieve-all-messages)610611### result.pipedFrom612613_Type:_ [`Array<Result | ExecaError>`](#result)614615[Results](#result) of the other subprocesses that were piped into this subprocess.616617This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.618619[More info.](pipe.md#result)620621### result.command622623_Type:_ `string`624625The file and [arguments](input.md#command-arguments) that were run.626627[More info.](debugging.md#command)628629### result.escapedCommand630631_Type:_ `string`632633Same as [`command`](#resultcommand) but escaped.634635With the [`shell`](#optionsshell) option, the command is not quoted, since the shell interprets it.636637[More info.](debugging.md#command)638639### result.cwd640641_Type:_ `string`642643The [current directory](#optionscwd) in which the command was run.644645[More info.](environment.md#current-directory)646647### result.durationMs648649_Type:_ `number`650651Duration of the subprocess, in milliseconds.652653[More info.](debugging.md#duration)654655### result.failed656657_Type:_ `boolean`658659Whether the subprocess failed to run.660661When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.662663[More info.](errors.md#subprocess-failure)664665## ExecaError666## ExecaSyncError667668_Type:_ `Error`669670Result of a subprocess [failed execution](errors.md#subprocess-failure).671672This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.673674This has the same shape as [successful results](#result), with the following additional properties.675676[More info.](errors.md)677678### error.message679680_Type:_ `string`681682Error message when the subprocess [failed](errors.md#subprocess-failure) to run.683684[More info.](errors.md#error-message)685686### error.shortMessage687688_Type:_ `string`689690This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).691692[More info.](errors.md#error-message)693694### error.originalMessage695696_Type:_ `string | undefined`697698Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.699700[More info.](errors.md#error-message)701702### error.cause703704_Type:_ `unknown | undefined`705706Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).707708This is usually an `Error` instance.709710[More info.](termination.md#error-message-and-stack-trace)711712### error.code713714_Type:_ `string | undefined`715716Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.717718### error.timedOut719720_Type:_ `boolean`721722Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.723724[More info.](termination.md#timeout)725726### error.isCanceled727728_Type:_ `boolean`729730Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.731732[More info.](termination.md#canceling)733734### error.isGracefullyCanceled735736_Type:_ `boolean`737738Whether the subprocess was canceled using both the [`cancelSignal`](#optionscancelsignal) and the [`gracefulCancel`](#optionsgracefulcancel) options.739740[More info.](termination.md#graceful-termination)741742### error.isMaxBuffer743744_Type:_ `boolean`745746Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.747748[More info.](output.md#big-output)749750### error.isTerminated751752_Type:_ `boolean`753754Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:755- The current process.756- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).757758[More info.](termination.md#signal-name-and-description)759760### error.isForcefullyTerminated761762_Type:_ `boolean`763764Whether the subprocess was terminated by the [`SIGKILL`](termination.md#sigkill) signal sent by the [`forceKillAfterDelay`](#optionsforcekillafterdelay) option.765766[More info.](termination.md#forceful-termination)767768### error.exitCode769770_Type:_ `number | undefined`771772The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.773774This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#errorsignal).775776[More info.](errors.md#exit-code)777778### error.signal779780_Type:_ `string | undefined`781782The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:783- The current process.784- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).785786If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.787788[More info.](termination.md#signal-name-and-description)789790### error.signalDescription791792_Type:_ `string | undefined`793794A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.795796If 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.797798[More info.](termination.md#signal-name-and-description)799800## Options801802_TypeScript:_ [`Options`](typescript.md) or [`SyncOptions`](typescript.md)\803_Type:_ `object`804805This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).806807The 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).808809### options.preferLocal810811_Type:_ `boolean`\812_Default:_ `true` with [`$`](#file-arguments-options), `false` otherwise813814Prefer locally installed binaries when looking for a binary to execute.815816[More info.](environment.md#local-binaries)817818### options.localDir819820_Type:_ `string | URL`\821_Default:_ [`cwd`](#optionscwd) option822823Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.824825[More info.](environment.md#local-binaries)826827### options.node828829_Type:_ `boolean`\830_Default:_ `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise831832If `true`, runs with Node.js. The first argument must be a Node.js file.833834The subprocess inherits the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) and version. This can be overridden using the [`nodeOptions`](#optionsnodeoptions) and [`nodePath`](#optionsnodepath) options.835836[More info.](node.md)837838### options.nodeOptions839840_Type:_ `string[]`\841_Default:_ [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)842843List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).844845Requires the [`node`](#optionsnode) option to be `true`.846847[More info.](node.md#nodejs-cli-flags)848849### options.nodePath850851_Type:_ `string | URL`\852_Default:_ [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)853854Path to the Node.js executable.855856Requires the [`node`](#optionsnode) option to be `true`.857858[More info.](node.md#nodejs-version)859860### options.shell861862_Type:_ `boolean | string | URL`\863_Default:_ `false`864865If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).866867Uses [`/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.868869We [recommend against](shell.md#avoiding-shells) using this option.870871[More info.](shell.md)872873### options.cwd874875_Type:_ `string | URL`\876_Default:_ `process.cwd()`877878Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.879880This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.881882[More info.](environment.md#current-directory)883884### options.env885886_Type:_ `object`\887_Default:_ `{}`888889[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).890891Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).892893[More info.](input.md#environment-variables)894895### options.extendEnv896897_Type:_ `boolean`\898_Default:_ `true`899900If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).901If `false`, only the `env` option is used, not `process.env`. However, when `env` has no `PATH`, the [`preferLocal`](#optionspreferlocal) and [`node`](#optionsnode) options still add their directories to `process.env.PATH`.902903[More info.](input.md#environment-variables)904905### options.input906907_Type:_ `string | Uint8Array | stream.Readable`908909Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).910911See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.912913[More info.](input.md#string-input)914915### options.inputFile916917_Type:_ `string | URL`918919Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).920921See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.922923[More info.](input.md#file-input)924925### options.stdin926927_TypeScript:_ [`StdinOption`](typescript.md) or [`StdinSyncOption`](typescript.md)\928_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)\929_Default:_ `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise930931How 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).932933This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.934935More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).936937### options.stdout938939_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\940_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)\941_Default:_ `pipe`942943How 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).944945This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.946947More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).948949### options.stderr950951_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\952_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)\953_Default:_ `pipe`954955How 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).956957This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.958959More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).960961### options.stdio962963_TypeScript:_ [`Options['stdio']`](typescript.md) or [`SyncOptions['stdio']`](typescript.md)\964_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} | {value: 'pipe' | 'inherit' | number | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}; input?: boolean}>` (or a tuple of those types)\965_Default:_ `pipe`966967Like 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'}`.968969A single string can be used [as a shortcut](output.md#shortcut).970971The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr). Some values have an ambiguous direction on an additional file descriptor (like `'pipe'`, `'inherit'`, a file or a transform), so they default to output. To use one for [input](input.md#additional-file-descriptors) instead, wrap it as `{value, input: true}`.972973More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).974975### options.all976977_Type:_ `boolean`\978_Default:_ `false`979980Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.981982[More info.](output.md#interleaved-output)983984### options.encoding985986_Type:_ `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\987_Default:_ `'utf8'`988989If 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).990991If it outputs binary data instead, this should be either:992- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).993- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#RFC_4648), [`'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.994995The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).996997String input passed with the [`input`](#optionsinput) or [`stdin`](#optionsstdin) option is always encoded with UTF-8, whatever this option is. With a text encoding, [`stdin` transforms](transform.md) also decode their input with UTF-8.998999[More info.](binary.md)10001001### options.lines10021003_Type:_ `boolean`\1004_Default:_ `false`10051006Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.10071008This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).10091010By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10111012[More info.](lines.md#simple-splitting)10131014### options.stripFinalNewline10151016_Type:_ `boolean`\1017_Default:_ `true`10181019Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10201021If the [`lines`](#optionslines) option is true, this applies to each output line instead.10221023By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10241025[More info.](lines.md#newlines)10261027### options.maxBuffer10281029_Type:_ `number`\1030_Default:_ `100_000_000`10311032Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).10331034By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10351036With [synchronous methods](execution.md#synchronous-execution), this cannot be enforced per file descriptor while the subprocess runs, since `spawnSync()` only accepts a single value, which limits the total output of all file descriptors. The `maxBuffer.stdout` value is used for it. The other file descriptors' own values are enforced from the output, once the subprocess ended, and cannot be higher than `maxBuffer.stdout`. Also, with synchronous methods, this is measured in bytes instead of [characters or lines](output.md#big-output), for the same reason.10371038When reached, [`error.isMaxBuffer`](#errorismaxbuffer) becomes `true`.10391040[More info.](output.md#big-output)10411042### options.buffer10431044_Type:_ `boolean`\1045_Default:_ `true`10461047When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.10481049By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10501051[More info.](output.md#low-memory)10521053### options.ipc10541055_Type:_ `boolean`\1056_Default:_ `true` if the [`node`](#optionsnode), [`ipcInput`](#optionsipcinput) or [`gracefulCancel`](#optionsgracefulcancel) option is set, `false` otherwise10571058Enables exchanging messages with the subprocess using [`subprocess.sendMessage(message)`](#subprocesssendmessagemessage-sendmessageoptions), [`subprocess.getOneMessage()`](#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](#subprocessgeteachmessagegeteachmessageoptions).10591060The subprocess must be a Node.js file.10611062[More info.](ipc.md)10631064### options.serialization10651066_Type:_ `'json' | 'advanced'`\1067_Default:_ `'advanced'`10681069Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.10701071[More info.](ipc.md#message-type)10721073### options.ipcInput10741075_Type_: [`Message`](ipc.md#message-type)10761077Sends an IPC message when the subprocess starts.10781079The subprocess must be a [Node.js file](#optionsnode). The value's [type](ipc.md#message-type) depends on the [`serialization`](#optionsserialization) option.10801081More info [here](ipc.md#send-an-initial-message) and [there](input.md#any-input-type).10821083### options.verbose10841085_Type:_ `'none' | 'short' | 'full' | Function`\1086_Default:_ `'none'`10871088If `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.10891090If `verbose` is `'full'` or a function, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), `stderr` and [IPC messages](ipc.md) are also printed.10911092A [function](#verbose-function) can be passed to customize logging. Please see [this page](debugging.md#custom-logging) for more information.10931094By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10951096[More info.](debugging.md#verbose-mode)10971098### options.reject10991100_Type:_ `boolean`\1101_Default:_ `true`11021103Setting this to `false` resolves the [result's promise](#return-value) with the [error](#execaerror) instead of rejecting it.11041105[More info.](errors.md#preventing-exceptions)11061107### options.timeout11081109_Type:_ `number`\1110_Default:_ `0`11111112If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds. It must be a non-negative integer, up to `2147483647` (about 24.8 days).11131114On timeout, [`error.timedOut`](#errortimedout) becomes `true`.11151116[More info.](termination.md#timeout)11171118### options.cancelSignal11191120_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)11211122When the `cancelSignal` is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), terminate the subprocess using a `SIGTERM` signal.11231124When aborted, [`error.isCanceled`](#erroriscanceled) becomes `true`.11251126[More info.](termination.md#canceling)11271128### options.gracefulCancel11291130_Type:_ `boolean`\1131_Default:_: `false`11321133When the [`cancelSignal`](#optionscancelsignal) option is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), do not send any [`SIGTERM`](termination.md#canceling). Instead, abort the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) returned by [`getCancelSignal()`](#getcancelsignal). The subprocess should use it to terminate gracefully.11341135The subprocess must be a [Node.js file](#optionsnode).11361137When aborted, [`error.isGracefullyCanceled`](#errorisgracefullycanceled) becomes `true`.11381139[More info.](termination.md#graceful-termination)11401141### options.forceKillAfterDelay11421143_Type:_ `number | boolean`\1144_Default:_ `5000`11451146If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL). The delay must be a non-negative integer, up to `2147483647` milliseconds (about 24.8 days). When `true`, the default `5000` is used. When `false`, the subprocess is not forcefully exited.11471148When this happens, [`error.isForcefullyTerminated`](#errorisforcefullyterminated) becomes `true`.11491150[More info.](termination.md#forceful-termination)11511152### options.killSignal11531154_Type:_ `string | number`\1155_Default:_ `'SIGTERM'`11561157Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.11581159This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).11601161[More info.](termination.md#default-signal)11621163### options.detached11641165_Type:_ `boolean`\1166_Default:_ `false`11671168Run the subprocess independently from the current process.11691170[More info.](environment.md#background-subprocess)11711172### options.cleanup11731174_Type:_ `boolean`\1175_Default:_ `true`11761177Kill the subprocess when the current process exits.11781179[More info.](termination.md#current-process-exit)11801181### options.killDescendants11821183_Type:_ `boolean`\1184_Default:_ `false`11851186When the subprocess is terminated by Execa, also terminate all of its descendant processes, instead of only the subprocess itself.11871188This is useful when the subprocess spawns its own processes, such as when using the [`shell`](#optionsshell) option.11891190On Unix, this spawns the subprocess in its own [process group](https://en.wikipedia.org/wiki/Process_group). On Windows, this uses [`taskkill`](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill).11911192This is best-effort: descendant processes that create their own process group or session are not terminated. Also, on Windows, descendants are not terminated once the subprocess exited, since its PID might then belong to an unrelated process.11931194[More info.](termination.md#killing-descendant-processes)11951196### options.uid11971198_Type:_ `number`\1199_Default:_ current user identifier12001201Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.12021203[More info.](windows.md#uid-and-gid)12041205### options.gid12061207_Type:_ `number`\1208_Default:_ current group identifier12091210Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.12111212[More info.](windows.md#uid-and-gid)12131214### options.argv012151216_Type:_ `string`\1217_Default:_ file being executed12181219Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.12201221### options.windowsHide12221223_Type:_ `boolean`\1224_Default:_ `true`12251226On Windows, do not create a new console window.12271228[More info.](windows.md#console-window)12291230### options.windowsVerbatimArguments12311232_Type:_ `boolean`\1233_Default:_ `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise12341235If `false`, escapes the command arguments on Windows.12361237[More info.](windows.md#escaping)12381239## Verbose function12401241_Type_: `(string, VerboseObject) => string | undefined`12421243Function passed to the [`verbose`](#optionsverbose) option to customize logging.12441245[More info.](debugging.md#custom-logging)12461247### Verbose object12481249_Type_: `VerboseObject` or `SyncVerboseObject`12501251Subprocess event object, for logging purpose, using the [`verbose`](#optionsverbose) option.12521253#### verboseObject.type12541255_Type_: `string`12561257Event type. This can be:1258- `'command'`: subprocess start1259- `'output'`: `stdout`/`stderr` [output](output.md#stdout-and-stderr)1260- `'ipc'`: IPC [output](ipc.md#retrieve-all-messages)1261- `'error'`: subprocess [failure](errors.md#subprocess-failure)1262- `'duration'`: subprocess success or failure12631264#### verboseObject.message12651266_Type_: `string`12671268Depending on [`verboseObject.type`](#verboseobjecttype), this is:1269- `'command'`: the [`result.escapedCommand`](#resultescapedcommand)1270- `'output'`: one line from [`result.stdout`](#resultstdout) or [`result.stderr`](#resultstderr)1271- `'ipc'`: one IPC message from [`result.ipcOutput`](#resultipcoutput)1272- `'error'`: the [`error.shortMessage`](#errorshortmessage)1273- `'duration'`: the [`result.durationMs`](#resultdurationms), formatted as `(done in 29ms)`12741275#### verboseObject.escapedCommand12761277_Type_: `string`12781279The file and [arguments](input.md#command-arguments) that were run. This is the same as [`result.escapedCommand`](#resultescapedcommand).12801281#### verboseObject.options12821283_Type_: [`Options`](#options-1) or [`SyncOptions`](#options-1)12841285The [options](#options-1) passed to the subprocess.12861287#### verboseObject.commandId12881289_Type_: `string`12901291Serial number identifying the subprocess within the current process. It is incremented from `'0'`.12921293This is helpful when multiple subprocesses are running at the same time.12941295This is similar to a [PID](https://en.wikipedia.org/wiki/Process_identifier) except it has no maximum limit, which means it never repeats. Also, it is usually shorter.12961297#### verboseObject.timestamp12981299_Type_: `Date`13001301Event date/time.13021303#### verboseObject.result13041305_Type_: [`Result`](#result), [`SyncResult`](#result) or `undefined`13061307Subprocess [result](#result).13081309This is `undefined` if [`verboseObject.type`](#verboseobjecttype) is `'command'`, `'output'` or `'ipc'`.13101311#### verboseObject.piped13121313_Type_: `boolean`13141315Whether this subprocess is the destination of another subprocess' [`pipe()`](#subprocesspipefile-arguments-options) method. This is `true` when it was spawned using the [template string](pipe.md#template-string-syntax) or [array](pipe.md#array-syntax) syntax, `false` otherwise.13161317## Transform options13181319A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.13201321A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.13221323[More info.](transform.md)13241325### transformOptions.transform13261327_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`13281329Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.13301331More info [here](transform.md#summary) and [there](transform.md#sharing-state).13321333### transformOptions.final13341335_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`13361337Create additional lines after the last one.13381339[More info.](transform.md#finalizing)13401341### transformOptions.binary13421343_Type:_ `boolean`\1344_Default:_ `false`13451346If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.13471348[More info.](binary.md#transforms)13491350### transformOptions.preserveNewlines13511352_Type:_ `boolean`\1353_Default:_ `false`13541355If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produce a single line.13561357[More info.](lines.md#transforms)13581359### transformOptions.objectMode13601361_Type:_ `boolean`\1362_Default:_ `false`13631364If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.13651366[More info.](transform.md#object-mode)13671368<hr>13691370[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1371[**Top**: Table of contents](../readme.md#documentation)