Skip to content
Myr

api.md

This file

Path

docs/api.md

1,336 lines · 52.4 KiB · Markdown

Last changed by

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

History of this file

Take it

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1–8why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 📔 API reference8

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 9why, one step back
9This lists all available [methods](#methods) and their [options](#options-1). This also describes the properties of the [subprocess](#subprocess), [result](#result) and [error](#execaerror) they return.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 10–16why, one step back
10
11## Methods1213### execa(file, arguments?, options?)1415`file`: `string | URL`\16`arguments`: `string[]`\

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 17why, one step back
17`options`: [`Options`](#options-1)\

Rename some types (#1009)ehmickybefore adoption2ef9186

line 18why, one step back
18_Returns_: [`ResultPromise`](#return-value)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 19–23why, one step back
19
20Executes a command using `file ...arguments`.2122More info on the [syntax](execution.md#array-syntax) and [escaping](escaping.md#array-syntax).23

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 24why, one step back
24### $(file, arguments?, options?)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 25why, one step back
25

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 26–28why, one step back
26`file`: `string | URL`\
27`arguments`: `string[]`\28`options`: [`Options`](#options-1)\

Rename some types (#1009)ehmickybefore adoption2ef9186

line 29why, one step back
29_Returns_: [`ResultPromise`](#return-value)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 30why, one step back
30

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 31why, one step back
31Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](scripts.md#script-files).

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 32why, one step back
32

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 33why, one step back
33This is the preferred method when executing multiple commands in a script file.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 34why, one step back
34

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 35why, one step back
35[More info.](scripts.md)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 36why, one step back
36

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 37why, one step back
37### execaNode(scriptPath, arguments?, options?)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 38why, one step back
38

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 39–42why, one step back
39`scriptPath`: `string | URL`\
40`arguments`: `string[]`\41`options`: [`Options`](#options-1)\42_Returns_: [`ResultPromise`](#return-value)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 43why, one step back
43

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 44–45why, one step back
44Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.
45Executes a Node.js file using `node scriptPath ...arguments`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 46why, one step back
46

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 47–50why, one step back
47This is the preferred method when executing Node.js files.
4849[More info.](node.md)50

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 51why, one step back
51### execaSync(file, arguments?, options?)

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 52–53why, one step back
52### $.sync(file, arguments?, options?)
53### $.s(file, arguments?, options?)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 54why, one step back
54

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 55–57why, one step back
55`file`: `string | URL`\
56`arguments`: `string[]`\57`options`: [`SyncOptions`](#options-1)\

Rename some types (#1009)ehmickybefore adoption2ef9186

line 58why, one step back
58_Returns_: [`SyncResult`](#return-value)

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

line 59why, one step back
59

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 60why, one step back
60Same as [`execa()`](#execafile-arguments-options) and [`$`](#file-arguments-options) but synchronous.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 61why, one step back
61

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 62why, one step back
62Returns a subprocess [`result`](#result) or throws an [`error`](#execasyncerror). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 63why, one step back
63

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 64–65why, one step back
64Those methods are discouraged as they hold the CPU and lack multiple features.
65

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 66–67why, one step back
66[More info.](execution.md#synchronous-execution)
67

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 68–73why, one step back
68### execa\`command\`
69### $\`command\`70### execaNode\`command\`71### execaSync\`command\`72### $.sync\`command\`73### $.s\`command\`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 74why, one step back
74

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 75–76why, one step back
75`command`: `string`\
76_Returns_: [`ResultPromise`](#return-value), [`SyncResult`](#return-value)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 77why, one step back
77

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 78why, one step back
78Same as [`execa()`](#execafile-arguments-options), [`$()`](#file-arguments-options), [`execaNode()`](#execanodescriptpath-arguments-options) and [`execaSync()`](#execasyncfile-arguments-options) but using a [template string](execution.md#template-string-syntax). `command` includes both the `file` and its `arguments`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 79why, one step back
79

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 80why, one step back
80More info on the [syntax](execution.md#template-string-syntax) and [escaping](escaping.md#template-string-syntax).

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 81why, one step back
81

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 82–87why, one step back
82### execa(options)\`command\`
83### $(options)\`command\`84### execaNode(options)\`command\`85### execaSync(options)\`command\`86### $.sync(options)\`command\`87### $.s(options)\`command\`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 88why, one step back
88

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 89–91why, one step back
89`command`: `string`\
90`options`: [`Options`](#options-1), [`SyncOptions`](#options-1)\91_Returns_: [`ResultPromise`](#return-value), [`SyncResult`](#return-value)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 92why, one step back
92

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 93why, one step back
93Same as [```execa`command` ```](#execacommand) but with [options](#options-1).

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 94why, one step back
94

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 95why, one step back
95[More info.](execution.md#template-string-syntax)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 96why, one step back
96

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 97–102why, one step back
97### execa(options)
98### $(options)99### execaNode(options)100### execaSync(options)101### $.sync(options)102### $.s(options)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 103why, one step back
103

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

lines 104–105why, one step back
104`options`: [`Options`](#options-1), [`SyncOptions`](#options-1)\
105_Returns_: [`ExecaMethod`](#execafile-arguments-options), [`ExecaScriptMethod`](#file-arguments-options), [`ExecaNodeMethod`](#execanodescriptpath-arguments-options), [`ExecaSyncMethod`](#execasyncfile-arguments-options), [`ExecaScriptSyncMethod`](#syncfile-arguments-options)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 106why, one step back
106

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 107why, one step back
107Returns a new instance of those methods but with different default [`options`](#options-1). Consecutive calls are merged to previous ones.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 108why, one step back
108

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 109why, one step back
109[More info.](execution.md#globalshared-options)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 110why, one step back
110

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

line 111why, one step back
111### parseCommandString(command)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 112–113why, one step back
112
113`command`: `string`\

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

line 114why, one step back
114_Returns_: `string[]`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 115why, one step back
115

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

line 116why, one step back
116Split 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 117–119why, one step back
117
118[More info.](escaping.md#user-defined-input)119

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 120why, one step back
120### sendMessage(message, sendMessageOptions?)

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 121–122why, one step back
121
122`message`: [`Message`](ipc.md#message-type)\

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 123why, one step back
123`sendMessageOptions`: [`SendMessageOptions`](#sendmessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 124–131why, one step back
124_Returns_: `Promise<void>`
125126Send a `message` to the parent process.127128This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.129130[More info.](ipc.md#exchanging-messages)131

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

lines 132–144why, one step back
132#### sendMessageOptions
133134_Type_: `object`135136#### sendMessageOptions.strict137138_Type_: `boolean`\139_Default_: `false`140141Throw when the other process is not receiving or listening to messages.142143[More info.](ipc.md#ensure-messages-are-received)144

Add `filter` option to `getOneMessage()` (#1076)ehmickybefore adoption571e052

line 145why, one step back
145### getOneMessage(getOneMessageOptions?)

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 146why, one step back
146

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 147why, one step back
147`getOneMessageOptions`: [`GetOneMessageOptions`](#getonemessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 148–155why, one step back
148_Returns_: [`Promise<Message>`](ipc.md#message-type)
149150Receive a single `message` from the parent process.151152This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.153154[More info.](ipc.md#exchanging-messages)155

Add `filter` option to `getOneMessage()` (#1076)ehmickybefore adoption571e052

lines 156–167why, one step back
156#### getOneMessageOptions
157158_Type_: `object`159160#### getOneMessageOptions.filter161162_Type_: [`(Message) => boolean`](ipc.md#message-type)163164Ignore any `message` that returns `false`.165166[More info.](ipc.md#filter-messages)167

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

line 168why, one step back
168#### getOneMessageOptions.reference

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 169why, one step back
169

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

lines 170–179why, one step back
170_Type_: `boolean`\
171_Default_: `true`172173Keep the subprocess alive while `getOneMessage()` is waiting.174175[More info.](ipc.md#keeping-the-subprocess-alive)176177### getEachMessage(getEachMessageOptions?)178179`getEachMessageOptions`: [`GetEachMessageOptions`](#geteachmessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 180–187why, one step back
180_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)
181182Iterate over each `message` from the parent process.183184This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.185186[More info.](ipc.md#listening-to-messages)187

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

lines 188–200why, one step back
188#### getEachMessageOptions
189190_Type_: `object`191192#### getEachMessageOptions.reference193194_Type_: `boolean`\195_Default_: `true`196197Keep the subprocess alive while `getEachMessage()` is waiting.198199[More info.](ipc.md#keeping-the-subprocess-alive)200

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

lines 201–210why, one step back
201### getCancelSignal()
202203_Returns_: [`Promise<AbortSignal>`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)204205Retrieves the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) shared by the [`cancelSignal`](#optionscancelsignal) option.206207This can only be called inside a subprocess. This requires the [`gracefulCancel`](#optionsgracefulcancel) option to be `true`.208209[More info.](termination.md#graceful-termination)210

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

line 211why, one step back
211## Return value

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 212why, one step back
212

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

lines 213–214why, one step back
213_TypeScript:_ [`ResultPromise`](typescript.md)\
214_Type:_ `Promise<object> | Subprocess`

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

line 215why, one step back
215

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 216why, one step back
216The return value of all [asynchronous methods](#methods) is both:

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

lines 217–218why, one step back
217- the [subprocess](#subprocess).
218- 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 219–221why, one step back
219
220[More info.](execution.md#subprocess)221

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

lines 222–223why, one step back
222## Subprocess
223

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

line 224why, one step back
224_TypeScript:_ [`Subprocess`](typescript.md)

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

lines 225–227why, one step back
225
226[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.227

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 228–248why, one step back
228### subprocess\[Symbol.asyncIterator\]()
229230_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)231232Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.233234[More info.](lines.md#progressive-splitting)235236### subprocess.iterable(readableOptions?)237238`readableOptions`: [`ReadableOptions`](#readableoptions)\239_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)240241Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.242243[More info.](lines.md#progressive-splitting)244245### subprocess.pipe(file, arguments?, options?)246247`file`: `string | URL`\248`arguments`: `string[]`\

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 249why, one step back
249`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 250–253why, one step back
250_Returns_: [`Promise<Result>`](#result)
251252[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.253

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 254why, one step back
254This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options-1) and [pipe-specific options](#pipeoptions) can be specified.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 255why, one step back
255

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 256–257why, one step back
256Like a subprocess, the return value can be [iterated](lines.md#progressive-splitting), [converted to a stream](streams.md#converting-a-subprocess-to-a-stream), or used for [IPC](ipc.md) with the destination subprocess.
257

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 258–263why, one step back
258[More info.](pipe.md#array-syntax)
259260### subprocess.pipe\`command\`261### subprocess.pipe(options)\`command\`262263`command`: `string`\

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 264why, one step back
264`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 265–266why, one step back
265_Returns_: [`Promise<Result>`](#result)
266

Fix broken Markdown links (#1119)ehmickybefore adoption8572eb1

line 267why, one step back
267Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](execution.md#template-string-syntax) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 268–272why, one step back
268
269[More info.](pipe.md#template-string-syntax)270271### subprocess.pipe(secondSubprocess, pipeOptions?)272

Rename some types (#1009)ehmickybefore adoption2ef9186

line 273why, one step back
273`secondSubprocess`: [`ResultPromise`](#return-value)\

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 274–276why, one step back
274`pipeOptions`: [`PipeOptions`](#pipeoptions)\
275_Returns_: [`Promise<Result>`](#result)276

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

line 277why, one step back
277Like [`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 278–282why, one step back
278
279[More info.](pipe.md#advanced-syntax)280281#### pipeOptions282

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 283why, one step back
283_Type:_ `object`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 284–286why, one step back
284
285#### pipeOptions.from286

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 287–288why, one step back
287_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\
288_Default:_ `"stdout"`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 289–297why, one step back
289
290Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.291292`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.293294[More info.](pipe.md#source-file-descriptor)295296#### pipeOptions.to297

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 298–299why, one step back
298_Type:_ `"stdin" | "fd3" | "fd4" | ...`\
299_Default:_ `"stdin"`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 300–306why, one step back
300
301Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.302303[More info.](pipe.md#destination-file-descriptor)304305#### pipeOptions.unpipeSignal306

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 307why, one step back
307_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 308–319why, one step back
308
309Unpipe the subprocess when the signal aborts.310311[More info.](pipe.md#unpipe)312313### subprocess.kill(signal, error?)314### subprocess.kill(error?)315316`signal`: `string | number`\317`error`: `Error`\318_Returns_: `boolean`319

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 320why, one step back
320Sends 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 321–329why, one step back
321
322This returns `false` when the signal could not be sent, for example when the subprocess has already exited.323324When 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).325326[More info.](termination.md)327328### subprocess.pid329

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 330why, one step back
330_Type:_ `number | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 331–337why, one step back
331
332Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).333334This is `undefined` if the subprocess failed to spawn.335336[More info.](termination.md#inter-process-termination)337

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 338why, one step back
338### subprocess.sendMessage(message, sendMessageOptions)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 339why, one step back
339

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 340why, one step back
340`message`: [`Message`](ipc.md#message-type)\

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 341why, one step back
341`sendMessageOptions`: [`SendMessageOptions`](#sendmessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 342why, one step back
342_Returns_: `Promise<void>`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 343why, one step back
343

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 344why, one step back
344Send a `message` to the subprocess.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 345why, one step back
345

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 346why, one step back
346This 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 347–349why, one step back
347
348[More info.](ipc.md#exchanging-messages)349

Add `filter` option to `getOneMessage()` (#1076)ehmickybefore adoption571e052

line 350why, one step back
350### subprocess.getOneMessage(getOneMessageOptions?)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 351why, one step back
351

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 352why, one step back
352`getOneMessageOptions`: [`GetOneMessageOptions`](#getonemessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 353why, one step back
353_Returns_: [`Promise<Message>`](ipc.md#message-type)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 354why, one step back
354

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 355why, one step back
355Receive a single `message` from the subprocess.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 356why, one step back
356

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 357why, one step back
357This 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 358–360why, one step back
358
359[More info.](ipc.md#exchanging-messages)360

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

line 361why, one step back
361### subprocess.getEachMessage(getEachMessageOptions?)

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 362why, one step back
362

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

line 363why, one step back
363`getEachMessageOptions`: [`GetEachMessageOptions`](#geteachmessageoptions)\

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 364–371why, one step back
364_Returns_: [`AsyncIterable<Message>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)
365366Iterate over each `message` from the subprocess.367368This requires the [`ipc`](#optionsipc) option to be `true`. The [type](ipc.md#message-type) of `message` depends on the [`serialization`](#optionsserialization) option.369370[More info.](ipc.md#listening-to-messages)371

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 372–373why, one step back
372### subprocess.stdin
373

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 374why, one step back
374_Type:_ [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 375–383why, one step back
375
376The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.377378This 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).379380[More info.](streams.md#manual-streaming)381382### subprocess.stdout383

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 384why, one step back
384_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 385–393why, one step back
385
386The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.387388This 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`.389390[More info.](streams.md#manual-streaming)391392### subprocess.stderr393

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 394why, one step back
394_Type:_ [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 395–403why, one step back
395
396The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.397398This 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`.399400[More info.](streams.md#manual-streaming)401402### subprocess.all403

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 404why, one step back
404_Type:_ [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 405–415why, one step back
405
406Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).407408This requires the [`all`](#optionsall) option to be `true`.409410This 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`.411412More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).413414### subprocess.stdio415

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 416why, one step back
416_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 417–434why, one step back
417
418The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.419420Each 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`.421422[More info.](streams.md#manual-streaming)423424### subprocess.readable(readableOptions?)425426`readableOptions`: [`ReadableOptions`](#readableoptions)\427_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream428429Converts the subprocess to a readable stream.430431[More info.](streams.md#converting-a-subprocess-to-a-stream)432433#### readableOptions434

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 435why, one step back
435_Type:_ `object`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 436–438why, one step back
436
437#### readableOptions.from438

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 439–440why, one step back
439_Type:_ `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\
440_Default:_ `"stdout"`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 441–449why, one step back
441
442Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.443444`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.445446[More info.](streams.md#different-file-descriptor)447448#### readableOptions.binary449

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 450–451why, one step back
450_Type:_ `boolean`\
451_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 452–462why, one step back
452
453If `false`, iterates over lines. Each line is a string.454455If `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)).456457This is always `true` when the [`encoding`](#optionsencoding) option is binary.458459More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).460461#### readableOptions.preserveNewlines462

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 463–464why, one step back
463_Type:_ `boolean`\
464_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 465–480why, one step back
465
466If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.467468[More info.](lines.md#iterable)469470### subprocess.writable(writableOptions?)471472`writableOptions`: [`WritableOptions`](#writableoptions)\473_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream474475Converts the subprocess to a writable stream.476477[More info.](streams.md#converting-a-subprocess-to-a-stream)478479#### writableOptions480

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 481why, one step back
481_Type:_ `object`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 482–484why, one step back
482
483#### writableOptions.to484

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 485–486why, one step back
485_Type:_ `"stdin" | "fd3" | "fd4" | ...`\
486_Default:_ `"stdin"`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 487–500why, one step back
487
488Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.489490[More info.](streams.md#different-file-descriptor)491492### subprocess.duplex(duplexOptions?)493494`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\495_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream496497Converts the subprocess to a duplex stream.498499[More info.](streams.md#converting-a-subprocess-to-a-stream)500

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 501–527why, one step back
501### subprocess.readableStream(readableOptions?)
502503`readableOptions`: [`ReadableOptions`](#readableoptions)\504_Returns_: [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) web stream505506Converts the subprocess to a readable web stream.507508[More info.](streams.md#converting-a-subprocess-to-a-web-stream)509510### subprocess.writableStream(writableOptions?)511512`writableOptions`: [`WritableOptions`](#writableoptions)\513_Returns_: [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) web stream514515Converts the subprocess to a writable web stream.516517[More info.](streams.md#converting-a-subprocess-to-a-web-stream)518519### subprocess.transformStream(duplexOptions?)520521`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\522_Returns_: [`{readable: ReadableStream, writable: WritableStream}`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream)523524Converts the subprocess to a [`{readable, writable}`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) pair of web streams.525526[More info.](streams.md#converting-a-subprocess-to-a-web-stream)527

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 528–529why, one step back
528## Result
529

Improve documentation of signal handling (#1105)ehmickybefore adoption01a4b42

line 530why, one step back
530_TypeScript:_ [`Result`](typescript.md) or [`SyncResult`](typescript.md)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 531why, one step back
531_Type:_ `object`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 532why, one step back
532

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 533why, one step back
533[Result](execution.md#result) of a subprocess successful execution.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 534–538why, one step back
534
535When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.536537### result.stdout538

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 539why, one step back
539_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 540–550why, one step back
540
541The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).542543This 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`.544545This 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).546547[More info.](output.md#stdout-and-stderr)548549### result.stderr550

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 551why, one step back
551_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 552–562why, one step back
552
553The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).554555This 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`.556557This 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).558559[More info.](output.md#stdout-and-stderr)560561### result.all562

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 563why, one step back
563_Type:_ `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 564–576why, one step back
564
565The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.566567This requires the [`all`](#optionsall) option to be `true`.568569This 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`.570571This 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).572573[More info.](output.md#interleaved-output)574575### result.stdio576

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 577why, one step back
577_Type:_ `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 578–586why, one step back
578
579The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).580581Items 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`.582583Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).584585[More info.](output.md#additional-file-descriptors)586

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 587why, one step back
587### result.ipcOutput

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 588why, one step back
588

Fix type of `result.ipc` (#1071)ehmickybefore adoption69152ec

line 589why, one step back
589_Type_: [`Message[]`](ipc.md#message-type)

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 590why, one step back
590

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 591why, one step back
591All the messages [sent by the subprocess](#sendmessagemessage-sendmessageoptions) to the current process.

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 592–596why, one step back
592
593This is empty unless the [`ipc`](#optionsipc) option is `true`. Also, this is empty if the [`buffer`](#optionsbuffer) option is `false`.594595[More info.](ipc.md#retrieve-all-messages)596

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 597–598why, one step back
597### result.pipedFrom
598

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 599why, one step back
599_Type:_ [`Array<Result | ExecaError>`](#result)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 600–608why, one step back
600
601[Results](#result) of the other subprocesses that were piped into this subprocess.602603This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.604605[More info.](pipe.md#result)606607### result.command608

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 609why, one step back
609_Type:_ `string`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 610–616why, one step back
610
611The file and [arguments](input.md#command-arguments) that were run.612613[More info.](debugging.md#command)614615### result.escapedCommand616

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 617why, one step back
617_Type:_ `string`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 618–624why, one step back
618
619Same as [`command`](#resultcommand) but escaped.620621[More info.](debugging.md#command)622623### result.cwd624

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 625why, one step back
625_Type:_ `string`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 626–632why, one step back
626
627The [current directory](#optionscwd) in which the command was run.628629[More info.](environment.md#current-directory)630631### result.durationMs632

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 633why, one step back
633_Type:_ `number`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 634–640why, one step back
634
635Duration of the subprocess, in milliseconds.636637[More info.](debugging.md#duration)638639### result.failed640

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 641why, one step back
641_Type:_ `boolean`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 642–644why, one step back
642
643Whether the subprocess failed to run.644

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 645–646why, one step back
645When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.
646

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 647–648why, one step back
647[More info.](errors.md#subprocess-failure)
648

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 649–650why, one step back
649## ExecaError
650## ExecaSyncError

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 651why, one step back
651

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 652why, one step back
652_Type:_ `Error`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 653–663why, one step back
653
654Result of a subprocess [failed execution](errors.md#subprocess-failure).655656This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.657658This has the same shape as [successful results](#result), with the following additional properties.659660[More info.](errors.md)661662### error.message663

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 664why, one step back
664_Type:_ `string`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 665–671why, one step back
665
666Error message when the subprocess [failed](errors.md#subprocess-failure) to run.667668[More info.](errors.md#error-message)669670### error.shortMessage671

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 672why, one step back
672_Type:_ `string`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 673–679why, one step back
673
674This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).675676[More info.](errors.md#error-message)677678### error.originalMessage679

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 680why, one step back
680_Type:_ `string | undefined`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 681–687why, one step back
681
682Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.683684[More info.](errors.md#error-message)685686### error.cause687

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 688why, one step back
688_Type:_ `unknown | undefined`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 689–697why, one step back
689
690Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).691692This is usually an `Error` instance.693694[More info.](termination.md#error-message-and-stack-trace)695696### error.code697

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 698why, one step back
698_Type:_ `string | undefined`

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 699–703why, one step back
699
700Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.701702### error.timedOut703

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 704why, one step back
704_Type:_ `boolean`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 705–709why, one step back
705
706Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.707708[More info.](termination.md#timeout)709

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 710why, one step back
710### error.isCanceled

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 711why, one step back
711

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 712why, one step back
712_Type:_ `boolean`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 713–717why, one step back
713
714Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.715716[More info.](termination.md#canceling)717

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

lines 718–725why, one step back
718### error.isGracefullyCanceled
719720_Type:_ `boolean`721722Whether the subprocess was canceled using both the [`cancelSignal`](#optionscancelsignal) and the [`gracefulCancel`](#optionsgracefulcancel) options.723724[More info.](termination.md#graceful-termination)725

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 726why, one step back
726### error.isMaxBuffer

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 727why, one step back
727

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 728why, one step back
728_Type:_ `boolean`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 729–733why, one step back
729
730Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.731732[More info.](output.md#big-output)733

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 734why, one step back
734### error.isTerminated

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 735why, one step back
735

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 736why, one step back
736_Type:_ `boolean`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 737–743why, one step back
737
738Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:739- The current process.740- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).741742[More info.](termination.md#signal-name-and-description)743

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 744–751why, one step back
744### error.isForcefullyTerminated
745746_Type:_ `boolean`747748Whether the subprocess was terminated by the [`SIGKILL`](termination.md#sigkill) signal sent by the [`forceKillAfterDelay`](#optionsforcekillafterdelay) option.749750[More info.](termination.md#forceful-termination)751

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 752why, one step back
752### error.exitCode

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 753why, one step back
753

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 754why, one step back
754_Type:_ `number | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 755–757why, one step back
755
756The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.757

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 758why, one step back
758This 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 759–761why, one step back
759
760[More info.](errors.md#exit-code)761

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 762why, one step back
762### error.signal

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 763why, one step back
763

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 764why, one step back
764_Type:_ `string | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 765–773why, one step back
765
766The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:767- The current process.768- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).769770If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.771772[More info.](termination.md#signal-name-and-description)773

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 774why, one step back
774### error.signalDescription

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 775why, one step back
775

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 776why, one step back
776_Type:_ `string | undefined`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 777–785why, one step back
777
778A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.779780If 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.781782[More info.](termination.md#signal-name-and-description)783784## Options785

Fix a typo (#1153)Reuben Thomasbefore adoption3fc8049

line 786why, one step back
786_TypeScript:_ [`Options`](typescript.md) or [`SyncOptions`](typescript.md)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 787why, one step back
787_Type:_ `object`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 788–794why, one step back
788
789This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).790791The 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).792793### options.preferLocal794

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 795–796why, one step back
795_Type:_ `boolean`\
796_Default:_ `true` with [`$`](#file-arguments-options), `false` otherwise

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 797–803why, one step back
797
798Prefer locally installed binaries when looking for a binary to execute.799800[More info.](environment.md#local-binaries)801802### options.localDir803

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 804–805why, one step back
804_Type:_ `string | URL`\
805_Default:_ [`cwd`](#optionscwd) option

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 806–812why, one step back
806
807Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.808809[More info.](environment.md#local-binaries)810811### options.node812

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 813–814why, one step back
813_Type:_ `boolean`\
814_Default:_ `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 815–817why, one step back
815
816If `true`, runs with Node.js. The first argument must be a Node.js file.817

Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5

lines 818–819why, one step back
818The 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.
819

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 820–823why, one step back
820[More info.](node.md)
821822### options.nodeOptions823

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 824why, one step back
824_Type:_ `string[]`\

Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)ehmickybefore adoption4878db5

line 825why, one step back
825_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 826–834why, one step back
826
827List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).828829Requires the [`node`](#optionsnode) option to be `true`.830831[More info.](node.md#nodejs-cli-flags)832833### options.nodePath834

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 835–836why, one step back
835_Type:_ `string | URL`\
836_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 837–845why, one step back
837
838Path to the Node.js executable.839840Requires the [`node`](#optionsnode) option to be `true`.841842[More info.](node.md#nodejs-version)843844### options.shell845

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 846–847why, one step back
846_Type:_ `boolean | string | URL`\
847_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 848–858why, one step back
848
849If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).850851Uses [`/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.852853We [recommend against](shell.md#avoiding-shells) using this option.854855[More info.](shell.md)856857### options.cwd858

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 859–860why, one step back
859_Type:_ `string | URL`\
860_Default:_ `process.cwd()`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 861–869why, one step back
861
862Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.863864This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.865866[More info.](environment.md#current-directory)867868### options.env869

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 870–871why, one step back
870_Type:_ `object`\
871_Default:_ [`process.env`](https://nodejs.org/api/process.html#processenv)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 872–880why, one step back
872
873[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).874875Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).876877[More info.](input.md#environment-variables)878879### options.extendEnv880

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 881–882why, one step back
881_Type:_ `boolean`\
882_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 883–890why, one step back
883
884If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).885If `false`, only the `env` option is used, not `process.env`.886887[More info.](input.md#environment-variables)888889### options.input890

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 891why, one step back
891_Type:_ `string | Uint8Array | stream.Readable`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 892–900why, one step back
892
893Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).894895See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.896897[More info.](input.md#string-input)898899### options.inputFile900

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 901why, one step back
901_Type:_ `string | URL`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 902–910why, one step back
902
903Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).904905See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.906907[More info.](input.md#file-input)908909### options.stdin910

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

line 911why, one step back
911_TypeScript:_ [`StdinOption`](typescript.md) or [`StdinSyncOption`](typescript.md)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 912–913why, one step back
912_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)\
913_Default:_ `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 914–922why, one step back
914
915How 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).916917This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.918919More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).920921### options.stdout922

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

line 923why, one step back
923_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 924–925why, one step back
924_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)\
925_Default:_ `pipe`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 926–934why, one step back
926
927How 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).928929This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.930931More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).932933### options.stderr934

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

line 935why, one step back
935_TypeScript:_ [`StdoutStderrOption`](typescript.md) or [`StdoutStderrSyncOption`](typescript.md)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 936–937why, one step back
936_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)\
937_Default:_ `pipe`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 938–946why, one step back
938
939How 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).940941This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.942943More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).944945### options.stdio946

Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058

line 947why, one step back
947_TypeScript:_ [`Options['stdio']`](typescript.md) or [`SyncOptions['stdio']`](typescript.md)\

Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba

line 948why, one step back
948_Type:_ `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream} | {value: 'pipe' | 'inherit' | number | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}; input?: boolean}>` (or a tuple of those types)\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 949why, one step back
949_Default:_ `pipe`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 950–954why, one step back
950
951Like 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'}`.952953A single string can be used [as a shortcut](output.md#shortcut).954

Generalize `{value, input}` to any direction-ambiguous stdio value (#1249)Sindre Sorhusbefore adoption9fbf5ba

line 955why, one step back
955The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr). Some values have an ambiguous direction on an additional file descriptor (like `'pipe'`, `'inherit'`, a file or a transform), so they default to output. To use one for [input](input.md#additional-file-descriptors) instead, wrap it as `{value, input: true}`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 956–960why, one step back
956
957More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).958959### options.all960

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 961–962why, one step back
961_Type:_ `boolean`\
962_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 963–969why, one step back
963
964Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.965966[More info.](output.md#interleaved-output)967968### options.encoding969

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 970–971why, one step back
970_Type:_ `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\
971_Default:_ `'utf8'`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 972–976why, one step back
972
973If 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).974975If it outputs binary data instead, this should be either:976- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 977why, one step back
977- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#RFC_4648), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 978–984why, one step back
978
979The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).980981[More info.](binary.md)982983### options.lines984

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 985–986why, one step back
985_Type:_ `boolean`\
986_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 987–997why, one step back
987
988Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.989990This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).991992By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).993994[More info.](lines.md#simple-splitting)995996### options.stripFinalNewline997

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 998–999why, one step back
998_Type:_ `boolean`\
999_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1000–1010why, one step back
1000
1001Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10021003If the [`lines`](#optionslines) option is true, this applies to each output line instead.10041005By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10061007[More info.](lines.md#newlines)10081009### options.maxBuffer1010

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1011–1012why, one step back
1011_Type:_ `number`\
1012_Default:_ `100_000_000`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1013–1017why, one step back
1013
1014Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).10151016By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).1017

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

lines 1018–1019why, one step back
1018When reached, [`error.isMaxBuffer`](#errorismaxbuffer) becomes `true`.
1019

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1020–1023why, one step back
1020[More info.](output.md#big-output)
10211022### options.buffer1023

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1024–1025why, one step back
1024_Type:_ `boolean`\
1025_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1026–1034why, one step back
1026
1027When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.10281029By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).10301031[More info.](output.md#low-memory)10321033### options.ipc1034

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 1035why, one step back
1035_Type:_ `boolean`\

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 1036why, one step back
1036_Default:_ `true` if the [`node`](#optionsnode), [`ipcInput`](#optionsipcinput) or [`gracefulCancel`](#optionsgracefulcancel) option is set, `false` otherwise

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1037why, one step back
1037

Fix broken Markdown links (#1119)ehmickybefore adoption8572eb1

line 1038why, one step back
1038Enables exchanging messages with the subprocess using [`subprocess.sendMessage(message)`](#subprocesssendmessagemessage-sendmessageoptions), [`subprocess.getOneMessage()`](#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](#subprocessgeteachmessagegeteachmessageoptions).

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1039why, one step back
1039

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 1040–1041why, one step back
1040The subprocess must be a Node.js file.
1041

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1042–1045why, one step back
1042[More info.](ipc.md)
10431044### options.serialization1045

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1046–1047why, one step back
1046_Type:_ `'json' | 'advanced'`\
1047_Default:_ `'advanced'`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1048–1051why, one step back
1048
1049Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.10501051[More info.](ipc.md#message-type)

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 1052–1061why, one step back
1052
1053### options.ipcInput10541055_Type_: [`Message`](ipc.md#message-type)10561057Sends an IPC message when the subprocess starts.10581059The subprocess must be a [Node.js file](#optionsnode). The value's [type](ipc.md#message-type) depends on the [`serialization`](#optionsserialization) option.10601061More 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 1062–1064why, one step back
1062
1063### options.verbose1064

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 1065why, one step back
1065_Type:_ `'none' | 'short' | 'full' | Function`\

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 1066why, one step back
1066_Default:_ `'none'`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1067–1069why, one step back
1067
1068If `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.1069

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 1070why, one step back
1070If `verbose` is `'full'` or a function, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), `stderr` and [IPC messages](ipc.md) are also printed.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1071why, one step back
1071

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 1072–1073why, one step back
1072A [function](#verbose-function) can be passed to customize logging. Please see [this page](debugging.md#custom-logging) for more information.
1073

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1074–1079why, one step back
1074By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).
10751076[More info.](debugging.md#verbose-mode)10771078### options.reject1079

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1080–1081why, one step back
1080_Type:_ `boolean`\
1081_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1082why, one step back
1082

Fix the type of the return value (#1007)ehmickybefore adoption0a13f2b

line 1083why, one step back
1083Setting 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 1084–1088why, one step back
1084
1085[More info.](errors.md#preventing-exceptions)10861087### options.timeout1088

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1089–1090why, one step back
1089_Type:_ `number`\
1090_Default:_ `0`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1091–1093why, one step back
1091
1092If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.1093

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 1094why, one step back
1094On timeout, [`error.timedOut`](#errortimedout) becomes `true`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1095–1099why, one step back
1095
1096[More info.](termination.md#timeout)10971098### options.cancelSignal1099

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 1100why, one step back
1100_Type:_ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1101why, one step back
1101

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 1102why, one step back
1102When the `cancelSignal` is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), terminate the subprocess using a `SIGTERM` signal.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1103why, one step back
1103

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 1104why, one step back
1104When aborted, [`error.isCanceled`](#erroriscanceled) becomes `true`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1105–1106why, one step back
1105
1106[More info.](termination.md#canceling)

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

lines 1107–1119why, one step back
1107
1108### options.gracefulCancel11091110_Type:_ `boolean`\1111_Default:_: `false`11121113When the [`cancelSignal`](#optionscancelsignal) option is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), do not send any [`SIGTERM`](termination.md#canceling). Instead, abort the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) returned by [`getCancelSignal()`](#getcancelsignal). The subprocess should use it to terminate gracefully.11141115The subprocess must be a [Node.js file](#optionsnode).11161117When aborted, [`error.isGracefullyCanceled`](#errorisgracefullycanceled) becomes `true`.11181119[More info.](termination.md#graceful-termination)

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1120–1122why, one step back
1120
1121### options.forceKillAfterDelay1122

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1123–1124why, one step back
1123_Type:_ `number | false`\
1124_Default:_ `5000`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1125–1126why, one step back
1125
1126If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 1127–1128why, one step back
1127
1128When this happens, [`error.isForcefullyTerminated`](#errorisforcefullyterminated) becomes `true`.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1129–1133why, one step back
1129
1130[More info.](termination.md#forceful-termination)11311132### options.killSignal1133

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1134–1135why, one step back
1134_Type:_ `string | number`\
1135_Default:_ `'SIGTERM'`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1136–1144why, one step back
1136
1137Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.11381139This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).11401141[More info.](termination.md#default-signal)11421143### options.detached1144

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1145–1146why, one step back
1145_Type:_ `boolean`\
1146_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1147–1153why, one step back
1147
1148Run the subprocess independently from the current process.11491150[More info.](environment.md#background-subprocess)11511152### options.cleanup1153

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1154–1155why, one step back
1154_Type:_ `boolean`\
1155_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1156–1162why, one step back
1156
1157Kill the subprocess when the current process exits.11581159[More info.](termination.md#current-process-exit)11601161### options.uid1162

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1163–1164why, one step back
1163_Type:_ `number`\
1164_Default:_ current user identifier

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1165–1171why, one step back
1165
1166Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.11671168[More info.](windows.md#uid-and-gid)11691170### options.gid1171

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1172–1173why, one step back
1172_Type:_ `number`\
1173_Default:_ current group identifier

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1174–1180why, one step back
1174
1175Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.11761177[More info.](windows.md#uid-and-gid)11781179### options.argv01180

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1181–1182why, one step back
1181_Type:_ `string`\
1182_Default:_ file being executed

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1183–1187why, one step back
1183
1184Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.11851186### options.windowsHide1187

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1188–1189why, one step back
1188_Type:_ `boolean`\
1189_Default:_ `true`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1190–1196why, one step back
1190
1191On Windows, do not create a new console window.11921193[More info.](windows.md#console-window)11941195### options.windowsVerbatimArguments1196

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1197–1198why, one step back
1197_Type:_ `boolean`\
1198_Default:_ `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1199–1201why, one step back
1199
1200If `false`, escapes the command arguments on Windows.1201

Improve documentation for `windowsVerbatimArguments` (#1149)ehmickybefore adoptionc4cb62a

line 1202why, one step back
1202[More info.](windows.md#escaping)

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 1203–1280why, one step back
1203
1204## Verbose function12051206_Type_: `(string, VerboseObject) => string | undefined`12071208Function passed to the [`verbose`](#optionsverbose) option to customize logging.12091210[More info.](debugging.md#custom-logging)12111212### Verbose object12131214_Type_: `VerboseObject` or `SyncVerboseObject`12151216Subprocess event object, for logging purpose, using the [`verbose`](#optionsverbose) option.12171218#### verboseObject.type12191220_Type_: `string`12211222Event type. This can be:1223- `'command'`: subprocess start1224- `'output'`: `stdout`/`stderr` [output](output.md#stdout-and-stderr)1225- `'ipc'`: IPC [output](ipc.md#retrieve-all-messages)1226- `'error'`: subprocess [failure](errors.md#subprocess-failure)1227- `'duration'`: subprocess success or failure12281229#### verboseObject.message12301231_Type_: `string`12321233Depending on [`verboseObject.type`](#verboseobjecttype), this is:1234- `'command'`: the [`result.escapedCommand`](#resultescapedcommand)1235- `'output'`: one line from [`result.stdout`](#resultstdout) or [`result.stderr`](#resultstderr)1236- `'ipc'`: one IPC message from [`result.ipcOutput`](#resultipcoutput)1237- `'error'`: the [`error.shortMessage`](#errorshortmessage)1238- `'duration'`: the [`result.durationMs`](#resultdurationms)12391240#### verboseObject.escapedCommand12411242_Type_: `string`12431244The file and [arguments](input.md#command-arguments) that were run. This is the same as [`result.escapedCommand`](#resultescapedcommand).12451246#### verboseObject.options12471248_Type_: [`Options`](#options-1) or [`SyncOptions`](#options-1)12491250The [options](#options-1) passed to the subprocess.12511252#### verboseObject.commandId12531254_Type_: `string`12551256Serial number identifying the subprocess within the current process. It is incremented from `'0'`.12571258This is helpful when multiple subprocesses are running at the same time.12591260This is similar to a [PID](https://en.wikipedia.org/wiki/Process_identifier) except it has no maximum limit, which means it never repeats. Also, it is usually shorter.12611262#### verboseObject.timestamp12631264_Type_: `Date`12651266Event date/time.12671268#### verboseObject.result12691270_Type_: [`Result`](#result), [`SyncResult`](#result) or `undefined`12711272Subprocess [result](#result).12731274This is `undefined` if [`verboseObject.type`](#verboseobjecttype) is `'command'`, `'output'` or `'ipc'`.12751276#### verboseObject.piped12771278_Type_: `boolean`12791280Whether another subprocess is [piped](pipe.md) into this subprocess. This is `false` when [`result.pipedFrom`](#resultfailed) is empty.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1281–1291why, one step back
1281
1282## Transform options12831284A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.12851286A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.12871288[More info.](transform.md)12891290### transformOptions.transform1291

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 1292why, one step back
1292_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1293–1299why, one step back
1293
1294Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.12951296More info [here](transform.md#summary) and [there](transform.md#sharing-state).12971298### transformOptions.final1299

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

line 1300why, one step back
1300_Type:_ `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1301–1307why, one step back
1301
1302Create additional lines after the last one.13031304[More info.](transform.md#finalizing)13051306### transformOptions.binary1307

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1308–1309why, one step back
1308_Type:_ `boolean`\
1309_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1310–1316why, one step back
1310
1311If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.13121313[More info.](binary.md#transforms)13141315### transformOptions.preserveNewlines1316

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1317–1318why, one step back
1317_Type:_ `boolean`\
1318_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 1319why, one step back
1319

Type the `std*` generator transform `chunk` argument (#1247)Sindre Sorhusbefore adoption0a7b4f8

line 1320why, one step back
1320If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produce a single line.

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1321–1325why, one step back
1321
1322[More info.](lines.md#transforms)13231324### transformOptions.objectMode1325

Fix style inconsistency in API reference (#1010)ehmickybefore adoption42bea7f

lines 1326–1327why, one step back
1326_Type:_ `boolean`\
1327_Default:_ `false`

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 1328–1336why, one step back
1328
1329If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.13301331[More info.](transform.md#object-mode)13321333<hr>13341335[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1336[**Top**: Table of contents](../readme.md#documentation)