api.md
This file
Path
docs/api.md
1,106 lines · 43.8 KiB · Markdown
Last changed by
Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
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–469why, 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)469Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 470why, one step back470### result.ipcOutputAdd `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 471why, one step back471Fix type of `result.ipc` (#1071)ehmickybefore adoption69152ec
line 472why, one step back472_Type_: [`Message[]`](ipc.md#message-type)Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 473–479why, one step back473474All the messages [sent by the subprocess](#sendmessagemessage) to the current process.475476This is empty unless the [`ipc`](#optionsipc) option is `true`. Also, this is empty if the [`buffer`](#optionsbuffer) option is `false`.477478[More info.](ipc.md#retrieve-all-messages)479Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 480–481why, one step back480### result.pipedFrom481Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 482why, one step back482_Type:_ [`Array<Result | ExecaError>`](#result)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 483–491why, one step back483484[Results](#result) of the other subprocesses that were piped into this subprocess.485486This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.487488[More info.](pipe.md#result)489490### result.command491Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 492why, one step back492_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 493–499why, one step back493494The file and [arguments](input.md#command-arguments) that were run.495496[More info.](debugging.md#command)497498### result.escapedCommand499Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 500why, one step back500_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 501–507why, one step back501502Same as [`command`](#resultcommand) but escaped.503504[More info.](debugging.md#command)505506### result.cwd507Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 508why, one step back508_Type:_ `string`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 509–515why, one step back509510The [current directory](#optionscwd) in which the command was run.511512[More info.](environment.md#current-directory)513514### result.durationMs515Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 516why, one step back516_Type:_ `number`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 517–523why, one step back517518Duration of the subprocess, in milliseconds.519520[More info.](debugging.md#duration)521522### result.failed523Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 524why, one step back524_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 525–527why, one step back525526Whether the subprocess failed to run.527Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 528–529why, one step back528When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.529Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 530–531why, one step back530[More info.](errors.md#subprocess-failure)531Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 532–533why, one step back532## ExecaError533## ExecaSyncErrorMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 534why, one step back534Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 535why, one step back535_Type:_ `Error`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 536–546why, one step back536537Result of a subprocess [failed execution](errors.md#subprocess-failure).538539This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.540541This has the same shape as [successful results](#result), with the following additional properties.542543[More info.](errors.md)544545### error.message546Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 547why, one step back547_Type:_ `string`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 548–554why, one step back548549Error message when the subprocess [failed](errors.md#subprocess-failure) to run.550551[More info.](errors.md#error-message)552553### error.shortMessage554Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 555why, one step back555_Type:_ `string`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 556–562why, one step back556557This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).558559[More info.](errors.md#error-message)560561### error.originalMessage562Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 563why, one step back563_Type:_ `string | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 564–570why, one step back564565Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.566567[More info.](errors.md#error-message)568569### error.cause570Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 571why, one step back571_Type:_ `unknown | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 572–580why, one step back572573Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).574575This is usually an `Error` instance.576577[More info.](termination.md#error-message-and-stack-trace)578579### error.code580Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 581why, one step back581_Type:_ `string | undefined`Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
lines 582–586why, one step back582583Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.584585### error.timedOut586Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 587why, one step back587_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 588–592why, one step back588589Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.590591[More info.](termination.md#timeout)592Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 593why, one step back593### error.isCanceledMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 594why, one step back594Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 595why, one step back595_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 596–600why, one step back596597Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.598599[More info.](termination.md#canceling)600Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 601why, one step back601### error.isMaxBufferMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 602why, one step back602Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 603why, one step back603_Type:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 604–608why, one step back604605Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.606607[More info.](output.md#big-output)608Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 609why, one step back609### error.isTerminatedMove 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:_ `boolean`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 612–618why, one step back612613Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:614- The current process.615- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).616617[More info.](termination.md#signal-name-and-description)618Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 619why, one step back619### error.exitCodeMove 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:_ `number | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 622–624why, one step back622623The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.624Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 625why, one step back625This 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 626–628why, one step back626627[More info.](errors.md#exit-code)628Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 629why, one step back629### error.signalMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 630why, one step back630Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 631why, one step back631_Type:_ `string | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 632–640why, one step back632633The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:634- The current process.635- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).636637If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.638639[More info.](termination.md#signal-name-and-description)640Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 641why, one step back641### error.signalDescriptionMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 642why, one step back642Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 643why, one step back643_Type:_ `string | undefined`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 644–652why, one step back644645A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.646647If 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.648649[More info.](termination.md#signal-name-and-description)650651## Options652Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 653why, one step back653_TypeScript:_ [`Options`](typescript.md) or [`SyncOptions`](typescript.md\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 654why, one step back654_Type:_ `object`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 655–661why, one step back655656This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).657658The 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).659660### options.preferLocal661Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 662–663why, one step back662_Type:_ `boolean`\663_Default:_ `true` with [`$`](#file-arguments-options), `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 664–670why, one step back664665Prefer locally installed binaries when looking for a binary to execute.666667[More info.](environment.md#local-binaries)668669### options.localDir670Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 671–672why, one step back671_Type:_ `string | URL`\672_Default:_ [`cwd`](#optionscwd) optionMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 673–679why, one step back673674Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.675676[More info.](environment.md#local-binaries)677678### options.node679Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 680–681why, one step back680_Type:_ `boolean`\681_Default:_ `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 682–684why, one step back682683If `true`, runs with Node.js. The first argument must be a Node.js file.684Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5
lines 685–686why, one step back685The 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.686Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 687–690why, one step back687[More info.](node.md)688689### options.nodeOptions690Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 691why, one step back691_Type:_ `string[]`\Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5
line 692why, one step back692_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 693–701why, one step back693694List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).695696Requires the [`node`](#optionsnode) option to be `true`.697698[More info.](node.md#nodejs-cli-flags)699700### options.nodePath701Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 702–703why, one step back702_Type:_ `string | URL`\703_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 704–712why, one step back704705Path to the Node.js executable.706707Requires the [`node`](#optionsnode) option to be `true`.708709[More info.](node.md#nodejs-version)710711### options.shell712Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 713–714why, one step back713_Type:_ `boolean | string | URL`\714_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 715–725why, one step back715716If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).717718Uses [`/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.719720We [recommend against](shell.md#avoiding-shells) using this option.721722[More info.](shell.md)723724### options.cwd725Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 726–727why, one step back726_Type:_ `string | URL`\727_Default:_ `process.cwd()`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 728–736why, one step back728729Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.730731This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.732733[More info.](environment.md#current-directory)734735### options.env736Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 737–738why, one step back737_Type:_ `object`\738_Default:_ [`process.env`](https://nodejs.org/api/process.html#processenv)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 739–747why, one step back739740[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).741742Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).743744[More info.](input.md#environment-variables)745746### options.extendEnv747Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 748–749why, one step back748_Type:_ `boolean`\749_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 750–757why, one step back750751If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).752If `false`, only the `env` option is used, not `process.env`.753754[More info.](input.md#environment-variables)755756### options.input757Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 758why, one step back758_Type:_ `string | Uint8Array | stream.Readable`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 759–767why, one step back759760Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).761762See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.763764[More info.](input.md#string-input)765766### options.inputFile767Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 768why, one step back768_Type:_ `string | URL`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 769–777why, one step back769770Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).771772See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.773774[More info.](input.md#file-input)775776### options.stdin777Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 778why, one step back778_TypeScript:_ [`StdinOption`](typescript.md) or [`StdinSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 779–780why, one step back779_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)\780_Default:_ `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 781–789why, one step back781782How 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).783784This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.785786More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).787788### options.stdout789Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 790why, one step back790_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 791–792why, one step back791_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)\792_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 793–801why, one step back793794How 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).795796This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.797798More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).799800### options.stderr801Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 802why, one step back802_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 803–804why, one step back803_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)\804_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 805–813why, one step back805806How 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).807808This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.809810More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).811812### options.stdio813Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 814why, one step back814_TypeScript:_ [`Options['stdio']`](typescript.md) or [`SyncOptions['stdio']`](typescript.md)\Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 815–816why, one step back815_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)\816_Default:_ `pipe`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 817–827why, one step back817818Like 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'}`.819820A single string can be used [as a shortcut](output.md#shortcut).821822The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).823824More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).825826### options.all827Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 828–829why, one step back828_Type:_ `boolean`\829_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 830–836why, one step back830831Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.832833[More info.](output.md#interleaved-output)834835### options.encoding836Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 837–838why, one step back837_Type:_ `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\838_Default:_ `'utf8'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 839–851why, one step back839840If 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).841842If it outputs binary data instead, this should be either:843- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).844- [`'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.845846The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).847848[More info.](binary.md)849850### options.lines851Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 852–853why, one step back852_Type:_ `boolean`\853_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 854–864why, one step back854855Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.856857This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).858859By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).860861[More info.](lines.md#simple-splitting)862863### options.stripFinalNewline864Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 865–866why, one step back865_Type:_ `boolean`\866_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 867–877why, one step back867868Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.869870If the [`lines`](#optionslines) option is true, this applies to each output line instead.871872By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).873874[More info.](lines.md#newlines)875876### options.maxBuffer877Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 878–879why, one step back878_Type:_ `number`\879_Default:_ `100_000_000`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 880–888why, one step back880881Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).882883By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).884885[More info.](output.md#big-output)886887### options.buffer888Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 889–890why, one step back889_Type:_ `boolean`\890_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 891–899why, one step back891892When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.893894By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).895896[More info.](output.md#low-memory)897898### options.ipc899Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 900why, one step back900_Type:_ `boolean`\Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 901why, one step back901_Default:_ `true` if either the [`node`](#optionsnode) option or the [`ipcInput`](#optionsipcinput) is set, `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
line 902why, one step back902Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68
line 903why, one step back903Enables 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
line 904why, one step back904Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 905–906why, one step back905The subprocess must be a Node.js file.906Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 907–910why, one step back907[More info.](ipc.md)908909### options.serialization910Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 911–912why, one step back911_Type:_ `'json' | 'advanced'`\912_Default:_ `'advanced'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 913–916why, one step back913914Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.915916[More info.](ipc.md#message-type)Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 917–926why, one step back917918### options.ipcInput919920_Type_: [`Message`](ipc.md#message-type)921922Sends an IPC message when the subprocess starts.923924The subprocess must be a [Node.js file](#optionsnode). The value's [type](ipc.md#message-type) depends on the [`serialization`](#optionsserialization) option.925926More info [here](ipc.md#send-an-initial-message) and [there](input.md#any-input-type).Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 927–929why, one step back927928### options.verbose929Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 930–931why, one step back930_Type:_ `'none' | 'short' | 'full'`\931_Default:_ `'none'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 932–934why, one step back932933If `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.934Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 935why, one step back935If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), `stderr` and [IPC messages](ipc.md) are also printed.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 936–942why, one step back936937By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).938939[More info.](debugging.md#verbose-mode)940941### options.reject942Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 943–944why, one step back943_Type:_ `boolean`\944_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 945why, one step back945Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b
line 946why, one step back946Setting 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 947–951why, one step back947948[More info.](errors.md#preventing-exceptions)949950### options.timeout951Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 952–953why, one step back952_Type:_ `number`\953_Default:_ `0`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 954–956why, one step back954955If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.956Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 957why, one step back957On timeout, [`result.timedOut`](#errortimedout) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 958–962why, one step back958959[More info.](termination.md#timeout)960961### options.cancelSignal962Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 963why, one step back963_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 964–966why, one step back964965You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).966Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec
line 967why, one step back967When `AbortController.abort()` is called, [`result.isCanceled`](#erroriscanceled) becomes `true`.Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 968–972why, one step back968969[More info.](termination.md#canceling)970971### options.forceKillAfterDelay972Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 973–974why, one step back973_Type:_ `number | false`\974_Default:_ `5000`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 975–981why, one step back975976If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).977978[More info.](termination.md#forceful-termination)979980### options.killSignal981Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 982–983why, one step back982_Type:_ `string | number`\983_Default:_ `'SIGTERM'`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 984–992why, one step back984985Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.986987This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).988989[More info.](termination.md#default-signal)990991### options.detached992Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 993–994why, one step back993_Type:_ `boolean`\994_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 995–1001why, one step back995996Run the subprocess independently from the current process.997998[More info.](environment.md#background-subprocess)9991000### options.cleanup1001Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1002–1003why, one step back1002_Type:_ `boolean`\1003_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1004–1010why, one step back10041005Kill the subprocess when the current process exits.10061007[More info.](termination.md#current-process-exit)10081009### options.uid1010Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1011–1012why, one step back1011_Type:_ `number`\1012_Default:_ current user identifierMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1013–1019why, one step back10131014Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.10151016[More info.](windows.md#uid-and-gid)10171018### options.gid1019Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1020–1021why, one step back1020_Type:_ `number`\1021_Default:_ current group identifierMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1022–1028why, one step back10221023Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.10241025[More info.](windows.md#uid-and-gid)10261027### options.argv01028Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1029–1030why, one step back1029_Type:_ `string`\1030_Default:_ file being executedMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1031–1035why, one step back10311032Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.10331034### options.windowsHide1035Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1036–1037why, one step back1036_Type:_ `boolean`\1037_Default:_ `true`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1038–1044why, one step back10381039On Windows, do not create a new console window.10401041[More info.](windows.md#console-window)10421043### options.windowsVerbatimArguments1044Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1045–1046why, one step back1045_Type:_ `boolean`\1046_Default:_ `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwiseMove API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1047–1061why, one step back10471048If `false`, escapes the command arguments on Windows.10491050[More info.](windows.md#cmdexe-escaping)10511052## Transform options10531054A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.10551056A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.10571058[More info.](transform.md)10591060### transformOptions.transform1061Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 1062why, one step back1062_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1063–1069why, one step back10631064Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.10651066More info [here](transform.md#summary) and [there](transform.md#sharing-state).10671068### transformOptions.final1069Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
line 1070why, one step back1070_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1071–1077why, one step back10711072Create additional lines after the last one.10731074[More info.](transform.md#finalizing)10751076### transformOptions.binary1077Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1078–1079why, one step back1078_Type:_ `boolean`\1079_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1080–1086why, one step back10801081If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.10821083[More info.](binary.md#transforms)10841085### transformOptions.preserveNewlines1086Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1087–1088why, one step back1087_Type:_ `boolean`\1088_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1089–1095why, one step back10891090If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.10911092[More info.](lines.md#transforms)10931094### transformOptions.objectMode1095Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f
lines 1096–1097why, one step back1096_Type:_ `boolean`\1097_Default:_ `false`Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1098–1106why, one step back10981099If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.11001101[More info.](transform.md#object-mode)11021103<hr>11041105[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1106[**Top**: Table of contents](../readme.md#documentation)