api.md
This file
Path
docs/api.md
1,084 lines · 43.1 KiB · Markdown
Last changed by
Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
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–85why, 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)85Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 86why, one step back86### parseCommandString(command)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 87–88why, one step back8788`command`: `string`\Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 89why, one step back89_Returns_: `string[]`Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 90why, one step back90Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 91why, one step back91Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 92–94why, one step back9293[More info.](escaping.md#user-defined-input)94Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
lines 95–125why, one step back95### sendMessage(message)9697`message`: [`Message`](ipc.md#message-type)\98_Returns_: `Promise<void>`99100Send a `message` to the parent process.101102This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.103104[More info.](ipc.md#exchanging-messages)105106### getOneMessage()107108_Returns_: [`Promise<Message>`](ipc.md#message-type)109110Receive a single `message` from the parent process.111112This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.113114[More info.](ipc.md#exchanging-messages)115116### getEachMessage()117118_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)119120Iterate over each `message` from the parent process.121122This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.123124[More info.](ipc.md#listening-to-messages)125Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 126why, one step back126## Return valueMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 127why, one step back127Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
lines 128–129why, one step back128_TypeScript:_ [`ResultPromise`](typescript.md)\129_Type:_ `Promise<object> | Subprocess`Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 130why, one step back130Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 131why, one step back131The return value of all [asynchronous methods](#methods) is both:Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 132–133why, one step back132- the [subprocess](#subprocess).133- 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 134–136why, one step back134135[More info.](execution.md#subprocess)136Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 137–138why, one step back137## Subprocess138Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 139why, one step back139_TypeScript:_ [`Subprocess`](typescript.md)Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
lines 140–142why, one step back140141[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.142Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 143–185why, one step back143### subprocess\[Symbol.asyncIterator\]()144145_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)146147Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.148149[More info.](lines.md#progressive-splitting)150151### subprocess.iterable(readableOptions?)152153`readableOptions`: [`ReadableOptions`](#readableoptions)\154_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)155156Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.157158[More info.](lines.md#progressive-splitting)159160### subprocess.pipe(file, arguments?, options?)161162`file`: `string | URL`\163`arguments`: `string[]`\164`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\165_Returns_: [`Promise<Result>`](#result)166167[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.168169This 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.170171[More info.](pipe.md#array-syntax)172173### subprocess.pipe\`command\`174### subprocess.pipe(options)\`command\`175176`command`: `string`\177`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\178_Returns_: [`Promise<Result>`](#result)179180Like [`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).181182[More info.](pipe.md#template-string-syntax)183184### subprocess.pipe(secondSubprocess, pipeOptions?)185Rename some types (#1009)ehmickybefore adoption2ef9186
line 186why, one step back186`secondSubprocess`: [`ResultPromise`](#return-value)\Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 187–189why, one step back187`pipeOptions`: [`PipeOptions`](#pipeoptions)\188_Returns_: [`Promise<Result>`](#result)189Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 190why, one step back190Like [`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 191–195why, one step back191192[More info.](pipe.md#advanced-syntax)193194#### pipeOptions195Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 196why, one step back196_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 197–199why, one step back197198#### pipeOptions.from199Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 200–201why, one step back200_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\201_Default:_ `"stdout"`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 202–210why, one step back202203Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.204205`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.206207[More info.](pipe.md#source-file-descriptor)208209#### pipeOptions.to210Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 211–212why, one step back211_Type:_ `"stdin" | "fd3" | "fd4" | ...`\212_Default:_ `"stdin"`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 213–219why, one step back213214Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.215216[More info.](pipe.md#destination-file-descriptor)217218#### pipeOptions.unpipeSignal219Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 220why, one step back220_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 221–232why, one step back221222Unpipe the subprocess when the signal aborts.223224[More info.](pipe.md#unpipe)225226### subprocess.kill(signal, error?)227### subprocess.kill(error?)228229`signal`: `string | number`\230`error`: `Error`\231_Returns_: `boolean`232Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 233why, one step back233Sends 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 234–242why, one step back234235This returns `false` when the signal could not be sent, for example when the subprocess has already exited.236237When 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).238239[More info.](termination.md)240241### subprocess.pid242Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 243why, one step back243_Type:_ `number | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 244–250why, one step back244245Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).246247This is `undefined` if the subprocess failed to spawn.248249[More info.](termination.md#inter-process-termination)250Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 251why, one step back251### subprocess.sendMessage(message)Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 252why, one step back252Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
lines 253–254why, one step back253`message`: [`Message`](ipc.md#message-type)\254_Returns_: `Promise<void>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 255why, one step back255Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 256why, one step back256Send a `message` to the subprocess.Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 257why, one step back257Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 258why, one step back258This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 259–261why, one step back259260[More info.](ipc.md#exchanging-messages)261Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 262why, one step back262### subprocess.getOneMessage()Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 263why, one step back263Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 264why, one step back264_Returns_: [`Promise<Message>`](ipc.md#message-type)Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 265why, one step back265Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 266why, one step back266Receive a single `message` from the subprocess.Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 267why, one step back267Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 268why, one step back268This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 269–271why, one step back269270[More info.](ipc.md#exchanging-messages)271Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
lines 272–281why, one step back272### subprocess.getEachMessage()273274_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)275276Iterate over each `message` from the subprocess.277278This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.279280[More info.](ipc.md#listening-to-messages)281Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 282–283why, one step back282### subprocess.stdin283Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 284why, one step back284_Type:_ [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 285–293why, one step back285286The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.287288This 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).289290[More info.](streams.md#manual-streaming)291292### subprocess.stdout293Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 294why, one step back294_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 295–303why, one step back295296The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.297298This 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`.299300[More info.](streams.md#manual-streaming)301302### subprocess.stderr303Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 304why, one step back304_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 305–313why, one step back305306The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.307308This 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`.309310[More info.](streams.md#manual-streaming)311312### subprocess.all313Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 314why, one step back314_Type:_ [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 315–325why, one step back315316Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).317318This requires the [`all`](#optionsall) option to be `true`.319320This 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`.321322More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).323324### subprocess.stdio325Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 326why, one step back326_Type:_ [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 327–344why, one step back327328The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.329330Each 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`.331332[More info.](streams.md#manual-streaming)333334### subprocess.readable(readableOptions?)335336`readableOptions`: [`ReadableOptions`](#readableoptions)\337_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream338339Converts the subprocess to a readable stream.340341[More info.](streams.md#converting-a-subprocess-to-a-stream)342343#### readableOptions344Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 345why, one step back345_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 346–348why, one step back346347#### readableOptions.from348Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 349–350why, one step back349_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\350_Default:_ `"stdout"`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 351–359why, one step back351352Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.353354`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.355356[More info.](streams.md#different-file-descriptor)357358#### readableOptions.binary359Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 360–361why, one step back360_Type:_ `boolean`\361_Default:_ `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 362–372why, one step back362363If `false`, iterates over lines. Each line is a string.364365If `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)).366367This is always `true` when the [`encoding`](#optionsencoding) option is binary.368369More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).370371#### readableOptions.preserveNewlines372Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 373–374why, one step back373_Type:_ `boolean`\374_Default:_ `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 375–390why, one step back375376If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.377378[More info.](lines.md#iterable)379380### subprocess.writable(writableOptions?)381382`writableOptions`: [`WritableOptions`](#writableoptions)\383_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream384385Converts the subprocess to a writable stream.386387[More info.](streams.md#converting-a-subprocess-to-a-stream)388389#### writableOptions390Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 391why, one step back391_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 392–394why, one step back392393#### writableOptions.to394Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 395–396why, one step back395_Type:_ `"stdin" | "fd3" | "fd4" | ...`\396_Default:_ `"stdin"`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 397–412why, one step back397398Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.399400[More info.](streams.md#different-file-descriptor)401402### subprocess.duplex(duplexOptions?)403404`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\405_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream406407Converts the subprocess to a duplex stream.408409[More info.](streams.md#converting-a-subprocess-to-a-stream)410411## Result412Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 413why, one step back413_TypeScript:_ [`Result`](typescript.md) or [`SyncResult`](typescript.md\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 414why, one step back414_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 415why, one step back415Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 416why, one step back416[Result](execution.md#result) of a subprocess successful execution.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 417–421why, one step back417418When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.419420### result.stdout421Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 422why, one step back422_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 423–433why, one step back423424The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).425426This 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`.427428This 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).429430[More info.](output.md#stdout-and-stderr)431432### result.stderr433Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 434why, one step back434_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 435–445why, one step back435436The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).437438This 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`.439440This 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).441442[More info.](output.md#stdout-and-stderr)443444### result.all445Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 446why, one step back446_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 447–459why, one step back447448The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.449450This requires the [`all`](#optionsall) option to be `true`.451452This 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`.453454This 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).455456[More info.](output.md#interleaved-output)457458### result.stdio459Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 460why, one step back460_Type:_ `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 461–471why, one step back461462The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).463464Items 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`.465466Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).467468[More info.](output.md#additional-file-descriptors)469470### result.pipedFrom471Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 472why, one step back472_Type:_ [`Array<Result | ExecaError>`](#result)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 473–481why, one step back473474[Results](#result) of the other subprocesses that were piped into this subprocess.475476This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.477478[More info.](pipe.md#result)479480### result.command481Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 482why, one step back482_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 483–489why, one step back483484The file and [arguments](input.md#command-arguments) that were run.485486[More info.](debugging.md#command)487488### result.escapedCommand489Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 490why, one step back490_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 491–497why, one step back491492Same as [`command`](#resultcommand) but escaped.493494[More info.](debugging.md#command)495496### result.cwd497Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 498why, one step back498_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 499–505why, one step back499500The [current directory](#optionscwd) in which the command was run.501502[More info.](environment.md#current-directory)503504### result.durationMs505Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 506why, one step back506_Type:_ `number`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 507–513why, one step back507508Duration of the subprocess, in milliseconds.509510[More info.](debugging.md#duration)511512### result.failed513Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 514why, one step back514_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 515–517why, one step back515516Whether the subprocess failed to run.517Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 518–519why, one step back518When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.519Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 520–521why, one step back520[More info.](errors.md#subprocess-failure)521Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 522–523why, one step back522## ExecaError523## ExecaSyncErrorMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 524why, one step back524Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 525why, one step back525_Type:_ `Error`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 526–536why, one step back526527Result of a subprocess [failed execution](errors.md#subprocess-failure).528529This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.530531This has the same shape as [successful results](#result), with the following additional properties.532533[More info.](errors.md)534535### error.message536Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 537why, one step back537_Type:_ `string`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 538–544why, one step back538539Error message when the subprocess [failed](errors.md#subprocess-failure) to run.540541[More info.](errors.md#error-message)542543### error.shortMessage544Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 545why, one step back545_Type:_ `string`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 546–552why, one step back546547This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).548549[More info.](errors.md#error-message)550551### error.originalMessage552Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 553why, one step back553_Type:_ `string | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 554–560why, one step back554555Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.556557[More info.](errors.md#error-message)558559### error.cause560Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 561why, one step back561_Type:_ `unknown | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 562–570why, one step back562563Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).564565This is usually an `Error` instance.566567[More info.](termination.md#error-message-and-stack-trace)568569### error.code570Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 571why, one step back571_Type:_ `string | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 572–576why, one step back572573Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.574575### error.timedOut576Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 577why, one step back577_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 578–582why, one step back578579Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.580581[More info.](termination.md#timeout)582Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 583why, one step back583### error.isCanceledMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 584why, one step back584Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 585why, one step back585_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 586–590why, one step back586587Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.588589[More info.](termination.md#canceling)590Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 591why, one step back591### error.isMaxBufferMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 592why, one step back592Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 593why, one step back593_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 594–598why, one step back594595Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.596597[More info.](output.md#big-output)598Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 599why, one step back599### error.isTerminatedMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 600why, one step back600Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 601why, one step back601_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 602–608why, one step back602603Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:604- The current process.605- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).606607[More info.](termination.md#signal-name-and-description)608Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 609why, one step back609### error.exitCodeMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 610why, one step back610Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 611why, one step back611_Type:_ `number | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 612–614why, one step back612613The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.614Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 615why, one step back615This 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 616–618why, one step back616617[More info.](errors.md#exit-code)618Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 619why, one step back619### error.signalMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 620why, one step back620Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 621why, one step back621_Type:_ `string | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 622–630why, one step back622623The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:624- The current process.625- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).626627If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.628629[More info.](termination.md#signal-name-and-description)630Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 631why, one step back631### error.signalDescriptionMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 632why, one step back632Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 633why, one step back633_Type:_ `string | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 634–642why, one step back634635A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.636637If 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.638639[More info.](termination.md#signal-name-and-description)640641## Options642Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 643why, one step back643_TypeScript:_ [`Options`](typescript.md) or [`SyncOptions`](typescript.md\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 644why, one step back644_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 645–651why, one step back645646This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).647648The 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).649650### options.preferLocal651Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 652–653why, one step back652_Type:_ `boolean`\653_Default:_ `true` with [`$`](#file-arguments-options), `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 654–660why, one step back654655Prefer locally installed binaries when looking for a binary to execute.656657[More info.](environment.md#local-binaries)658659### options.localDir660Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 661–662why, one step back661_Type:_ `string | URL`\662_Default:_ [`cwd`](#optionscwd) optionMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 663–669why, one step back663664Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.665666[More info.](environment.md#local-binaries)667668### options.node669Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 670–671why, one step back670_Type:_ `boolean`\671_Default:_ `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 672–674why, one step back672673If `true`, runs with Node.js. The first argument must be a Node.js file.674Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5
lines 675–676why, one step back675The 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.676Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 677–680why, one step back677[More info.](node.md)678679### options.nodeOptions680Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 681why, one step back681_Type:_ `string[]`\Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5
line 682why, one step back682_Default:_ [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 683–691why, one step back683684List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).685686Requires the [`node`](#optionsnode) option to be `true`.687688[More info.](node.md#nodejs-cli-flags)689690### options.nodePath691Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 692–693why, one step back692_Type:_ `string | URL`\693_Default:_ [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 694–702why, one step back694695Path to the Node.js executable.696697Requires the [`node`](#optionsnode) option to be `true`.698699[More info.](node.md#nodejs-version)700701### options.shell702Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 703–704why, one step back703_Type:_ `boolean | string | URL`\704_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 705–715why, one step back705706If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).707708Uses [`/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.709710We [recommend against](shell.md#avoiding-shells) using this option.711712[More info.](shell.md)713714### options.cwd715Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 716–717why, one step back716_Type:_ `string | URL`\717_Default:_ `process.cwd()`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 718–726why, one step back718719Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.720721This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.722723[More info.](environment.md#current-directory)724725### options.env726Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 727–728why, one step back727_Type:_ `object`\728_Default:_ [`process.env`](https://nodejs.org/api/process.html#processenv)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 729–737why, one step back729730[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).731732Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).733734[More info.](input.md#environment-variables)735736### options.extendEnv737Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 738–739why, one step back738_Type:_ `boolean`\739_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 740–747why, one step back740741If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).742If `false`, only the `env` option is used, not `process.env`.743744[More info.](input.md#environment-variables)745746### options.input747Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 748why, one step back748_Type:_ `string | Uint8Array | stream.Readable`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 749–757why, one step back749750Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).751752See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.753754[More info.](input.md#string-input)755756### options.inputFile757Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 758why, one step back758_Type:_ `string | URL`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 759–767why, one step back759760Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).761762See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.763764[More info.](input.md#file-input)765766### options.stdin767Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 768why, one step back768_TypeScript:_ [`StdinOption`](typescript.md) or [`StdinSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 769–770why, one step back769_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)\770_Default:_ `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 771–779why, one step back771772How 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).773774This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.775776More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).777778### options.stdout779Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 780why, one step back780_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 781–782why, one step back781_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)\782_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 783–791why, one step back783784How 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).785786This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.787788More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).789790### options.stderr791Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 792why, one step back792_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 793–794why, one step back793_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)\794_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 795–803why, one step back795796How 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).797798This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.799800More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).801802### options.stdio803Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 804why, one step back804_TypeScript:_ [`Options['stdio']`](typescript.md) or [`SyncOptions['stdio']`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 805–806why, one step back805_Type:_ `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\806_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 807–817why, one step back807808Like 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'}`.809810A single string can be used [as a shortcut](output.md#shortcut).811812The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).813814More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).815816### options.all817Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 818–819why, one step back818_Type:_ `boolean`\819_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 820–826why, one step back820821Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.822823[More info.](output.md#interleaved-output)824825### options.encoding826Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 827–828why, one step back827_Type:_ `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\828_Default:_ `'utf8'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 829–841why, one step back829830If 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).831832If it outputs binary data instead, this should be either:833- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).834- [`'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.835836The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).837838[More info.](binary.md)839840### options.lines841Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 842–843why, one step back842_Type:_ `boolean`\843_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 844–854why, one step back844845Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.846847This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).848849By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).850851[More info.](lines.md#simple-splitting)852853### options.stripFinalNewline854Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 855–856why, one step back855_Type:_ `boolean`\856_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 857–867why, one step back857858Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.859860If the [`lines`](#optionslines) option is true, this applies to each output line instead.861862By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).863864[More info.](lines.md#newlines)865866### options.maxBuffer867Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 868–869why, one step back868_Type:_ `number`\869_Default:_ `100_000_000`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 870–878why, one step back870871Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).872873By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).874875[More info.](output.md#big-output)876877### options.buffer878Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 879–880why, one step back879_Type:_ `boolean`\880_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 881–889why, one step back881882When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.883884By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).885886[More info.](output.md#low-memory)887888### options.ipc889Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 890–891why, one step back890_Type:_ `boolean`\891_Default:_ `true` if the [`node`](#optionsnode) option is enabled, `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 892why, one step back892Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 893why, one step back893Enables exchanging messages with the subprocess using [`subprocess.sendMessage(message)`](#subprocesssendmessagemessage), [`subprocess.getOneMessage()`](#subprocessgetonemessage) and [`subprocess.getEachMessage()`](#subprocessgeteachmessage).Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 894–898why, one step back894895[More info.](ipc.md)896897### options.serialization898Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 899–900why, one step back899_Type:_ `'json' | 'advanced'`\900_Default:_ `'advanced'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 901–907why, one step back901902Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.903904[More info.](ipc.md#message-type)905906### options.verbose907Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 908–909why, one step back908_Type:_ `'none' | 'short' | 'full'`\909_Default:_ `'none'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 910–920why, one step back910911If `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.912913If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.914915By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).916917[More info.](debugging.md#verbose-mode)918919### options.reject920Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 921–922why, one step back921_Type:_ `boolean`\922_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 923why, one step back923Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 924why, one step back924Setting 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 925–929why, one step back925926[More info.](errors.md#preventing-exceptions)927928### options.timeout929Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 930–931why, one step back930_Type:_ `number`\931_Default:_ `0`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 932–934why, one step back932933If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.934Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 935why, one step back935On timeout, [`result.timedOut`](#errortimedout) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 936–940why, one step back936937[More info.](termination.md#timeout)938939### options.cancelSignal940Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 941why, one step back941_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 942–944why, one step back942943You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).944Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 945why, one step back945When `AbortController.abort()` is called, [`result.isCanceled`](#erroriscanceled) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 946–950why, one step back946947[More info.](termination.md#canceling)948949### options.forceKillAfterDelay950Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 951–952why, one step back951_Type:_ `number | false`\952_Default:_ `5000`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 953–959why, one step back953954If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).955956[More info.](termination.md#forceful-termination)957958### options.killSignal959Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 960–961why, one step back960_Type:_ `string | number`\961_Default:_ `'SIGTERM'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 962–970why, one step back962963Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.964965This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).966967[More info.](termination.md#default-signal)968969### options.detached970Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 971–972why, one step back971_Type:_ `boolean`\972_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 973–979why, one step back973974Run the subprocess independently from the current process.975976[More info.](environment.md#background-subprocess)977978### options.cleanup979Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 980–981why, one step back980_Type:_ `boolean`\981_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 982–988why, one step back982983Kill the subprocess when the current process exits.984985[More info.](termination.md#current-process-exit)986987### options.uid988Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 989–990why, one step back989_Type:_ `number`\990_Default:_ current user identifierMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 991–997why, one step back991992Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.993994[More info.](windows.md#uid-and-gid)995996### options.gid997Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 998–999why, one step back998_Type:_ `number`\999_Default:_ current group identifierMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1000–1006why, one step back10001001Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.10021003[More info.](windows.md#uid-and-gid)10041005### options.argv01006Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1007–1008why, one step back1007_Type:_ `string`\1008_Default:_ file being executedMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1009–1013why, one step back10091010Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.10111012### options.windowsHide1013Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1014–1015why, one step back1014_Type:_ `boolean`\1015_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1016–1022why, one step back10161017On Windows, do not create a new console window.10181019[More info.](windows.md#console-window)10201021### options.windowsVerbatimArguments1022Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1023–1024why, one step back1023_Type:_ `boolean`\1024_Default:_ `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1025–1039why, one step back10251026If `false`, escapes the command arguments on Windows.10271028[More info.](windows.md#cmdexe-escaping)10291030## Transform options10311032A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.10331034A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.10351036[More info.](transform.md)10371038### transformOptions.transform1039Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 1040why, one step back1040_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1041–1047why, one step back10411042Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.10431044More info [here](transform.md#summary) and [there](transform.md#sharing-state).10451046### transformOptions.final1047Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 1048why, one step back1048_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1049–1055why, one step back10491050Create additional lines after the last one.10511052[More info.](transform.md#finalizing)10531054### transformOptions.binary1055Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1056–1057why, one step back1056_Type:_ `boolean`\1057_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1058–1064why, one step back10581059If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.10601061[More info.](binary.md#transforms)10621063### transformOptions.preserveNewlines1064Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1065–1066why, one step back1065_Type:_ `boolean`\1066_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1067–1073why, one step back10671068If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.10691070[More info.](lines.md#transforms)10711072### transformOptions.objectMode1073Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1074–1075why, one step back1074_Type:_ `boolean`\1075_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1076–1084why, one step back10761077If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.10781079[More info.](transform.md#object-mode)10801081<hr>10821083[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1084[**Top**: Table of contents](../readme.md#documentation)