Skip to content
Myr

Move API reference to its own page (#996)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent ceb1069 · Browse files · 21 files+1151 added−1137 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

21 files+1151 added−1137 removed

  • other:+1151 added−1137 removed

21 files+1151 added−1137 removed

added:docs/api.md+1029 added
1<picture>2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 📔 API reference89This lists all available [methods](#methods) and their [options](#options). This also describes the properties of the [subprocess](#subprocess), [result](#result) and [error](#execaerror) they return.1011## Methods1213### execa(file, arguments?, options?)1415`file`: `string | URL`\16`arguments`: `string[]`\17`options`: [`Options`](#options)\18_Returns_: [`Subprocess`](#subprocess)1920Executes a command using `file ...arguments`.2122More info on the [syntax](execution.md#array-syntax) and [escaping](escaping.md#array-syntax).2324### execa\`command\`25### execa(options)\`command\`2627`command`: `string`\28`options`: [`Options`](#options)\29_Returns_: [`Subprocess`](#subprocess)3031Executes a command. `command` is a [template string](execution.md#template-string-syntax) that includes both the `file` and its `arguments`.3233More info on the [syntax](execution.md#template-string-syntax) and [escaping](escaping.md#template-string-syntax).3435### execa(options)3637`options`: [`Options`](#options)\38_Returns_: [`execa`](#execafile-arguments-options)3940Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.4142[More info.](execution.md#globalshared-options)4344### execaSync(file, arguments?, options?)45### execaSync\`command\`4647Same as [`execa()`](#execafile-arguments-options) but synchronous.4849Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.5051[More info.](execution.md#synchronous-execution)5253### $(file, arguments?, options?)5455`file`: `string | URL`\56`arguments`: `string[]`\57`options`: [`Options`](#options)\58_Returns_: [`Subprocess`](#subprocess)5960Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](scripts.md#script-files).6162Just like `execa()`, this can use the [template string syntax](execution.md#template-string-syntax) or [bind options](execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.6364This is the preferred method when executing multiple commands in a script file.6566[More info.](scripts.md)6768### execaNode(scriptPath, arguments?, options?)6970`scriptPath`: `string | URL`\71`arguments`: `string[]`\72`options`: [`Options`](#options)\73_Returns_: [`Subprocess`](#subprocess)7475Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.76Executes a Node.js file using `node scriptPath ...arguments`.7778Just like `execa()`, this can use the [template string syntax](execution.md#template-string-syntax) or [bind options](execution.md#globalshared-options).7980This is the preferred method when executing Node.js files.8182[More info.](node.md)8384### execaCommand(command, options?)8586`command`: `string`\87`options`: [`Options`](#options)\88_Returns_: [`Subprocess`](#subprocess)8990Executes a command. `command` is a string that includes both the `file` and its `arguments`.9192This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.9394Just like `execa()`, this can [bind options](execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.9596[More info.](escaping.md#user-defined-input)9798## Subprocess99100The return value of all [asynchronous methods](#methods) is both:101- a `Promise` resolving or rejecting with a subprocess [`result`](#result).102- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.103104[More info.](execution.md#subprocess)105106### subprocess\[Symbol.asyncIterator\]()107108_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)109110Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.111112[More info.](lines.md#progressive-splitting)113114### subprocess.iterable(readableOptions?)115116`readableOptions`: [`ReadableOptions`](#readableoptions)\117_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)118119Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.120121[More info.](lines.md#progressive-splitting)122123### subprocess.pipe(file, arguments?, options?)124125`file`: `string | URL`\126`arguments`: `string[]`\127`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\128_Returns_: [`Promise<Result>`](#result)129130[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.131132This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options) and [pipe-specific options](#pipeoptions) can be specified.133134[More info.](pipe.md#array-syntax)135136### subprocess.pipe\`command\`137### subprocess.pipe(options)\`command\`138139`command`: `string`\140`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\141_Returns_: [`Promise<Result>`](#result)142143Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).144145[More info.](pipe.md#template-string-syntax)146147### subprocess.pipe(secondSubprocess, pipeOptions?)148149`secondSubprocess`: [`execa()` return value](#subprocess)\150`pipeOptions`: [`PipeOptions`](#pipeoptions)\151_Returns_: [`Promise<Result>`](#result)152153Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#subprocess) of another [`execa()`](#execafile-arguments-options) call instead.154155[More info.](pipe.md#advanced-syntax)156157#### pipeOptions158159Type: `object`160161#### pipeOptions.from162163Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\164Default: `"stdout"`165166Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.167168`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.169170[More info.](pipe.md#source-file-descriptor)171172#### pipeOptions.to173174Type: `"stdin" | "fd3" | "fd4" | ...`\175Default: `"stdin"`176177Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.178179[More info.](pipe.md#destination-file-descriptor)180181#### pipeOptions.unpipeSignal182183Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)184185Unpipe the subprocess when the signal aborts.186187[More info.](pipe.md#unpipe)188189### subprocess.kill(signal, error?)190### subprocess.kill(error?)191192`signal`: `string | number`\193`error`: `Error`\194_Returns_: `boolean`195196Sends 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](#resultisterminated) the subprocess.197198This returns `false` when the signal could not be sent, for example when the subprocess has already exited.199200When 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).201202[More info.](termination.md)203204### subprocess.pid205206_Type_: `number | undefined`207208Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).209210This is `undefined` if the subprocess failed to spawn.211212[More info.](termination.md#inter-process-termination)213214### subprocess.send(message)215216`message`: `unknown`\217_Returns_: `boolean`218219Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.220The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).221222This returns `true` on success.223224This requires the [`ipc`](#optionsipc) option to be `true`.225226[More info.](ipc.md#exchanging-messages)227228### subprocess.on('message', (message) => void)229230`message`: `unknown`231232Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.233The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).234235This requires the [`ipc`](#optionsipc) option to be `true`.236237[More info.](ipc.md#exchanging-messages)238239### subprocess.stdin240241Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)242243The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.244245This 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).246247[More info.](streams.md#manual-streaming)248249### subprocess.stdout250251Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)252253The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.254255This 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`.256257[More info.](streams.md#manual-streaming)258259### subprocess.stderr260261Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)262263The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.264265This 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`.266267[More info.](streams.md#manual-streaming)268269### subprocess.all270271Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)272273Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).274275This requires the [`all`](#optionsall) option to be `true`.276277This 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`.278279More info on [interleaving](output.md#interleaved-output) and [streaming](streams.md#manual-streaming).280281### subprocess.stdio282283Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)284285The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.286287Each 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`.288289[More info.](streams.md#manual-streaming)290291### subprocess.readable(readableOptions?)292293`readableOptions`: [`ReadableOptions`](#readableoptions)\294_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream295296Converts the subprocess to a readable stream.297298[More info.](streams.md#converting-a-subprocess-to-a-stream)299300#### readableOptions301302Type: `object`303304#### readableOptions.from305306Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\307Default: `"stdout"`308309Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.310311`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.312313[More info.](streams.md#different-file-descriptor)314315#### readableOptions.binary316317Type: `boolean`\318Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)319320If `false`, iterates over lines. Each line is a string.321322If `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)).323324This is always `true` when the [`encoding`](#optionsencoding) option is binary.325326More info for [iterables](binary.md#iterable) and [streams](binary.md#streams).327328#### readableOptions.preserveNewlines329330Type: `boolean`\331Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)332333If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.334335[More info.](lines.md#iterable)336337### subprocess.writable(writableOptions?)338339`writableOptions`: [`WritableOptions`](#writableoptions)\340_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream341342Converts the subprocess to a writable stream.343344[More info.](streams.md#converting-a-subprocess-to-a-stream)345346#### writableOptions347348Type: `object`349350#### writableOptions.to351352Type: `"stdin" | "fd3" | "fd4" | ...`\353Default: `"stdin"`354355Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.356357[More info.](streams.md#different-file-descriptor)358359### subprocess.duplex(duplexOptions?)360361`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\362_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream363364Converts the subprocess to a duplex stream.365366[More info.](streams.md#converting-a-subprocess-to-a-stream)367368## Result369370Type: `object`371372[Result](execution.md#result) of a subprocess execution.373374When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.375376### result.stdout377378Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`379380The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).381382This 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`.383384This 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).385386[More info.](output.md#stdout-and-stderr)387388### result.stderr389390Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`391392The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).393394This 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`.395396This 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).397398[More info.](output.md#stdout-and-stderr)399400### result.all401402Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`403404The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.405406This requires the [`all`](#optionsall) option to be `true`.407408This 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`.409410This 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).411412[More info.](output.md#interleaved-output)413414### result.stdio415416Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`417418The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).419420Items 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`.421422Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).423424[More info.](output.md#additional-file-descriptors)425426### result.pipedFrom427428Type: [`Array<Result | ExecaError>`](#result)429430[Results](#result) of the other subprocesses that were piped into this subprocess.431432This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.433434[More info.](pipe.md#result)435436### result.command437438Type: `string`439440The file and [arguments](input.md#command-arguments) that were run.441442[More info.](debugging.md#command)443444### result.escapedCommand445446Type: `string`447448Same as [`command`](#resultcommand) but escaped.449450[More info.](debugging.md#command)451452### result.cwd453454Type: `string`455456The [current directory](#optionscwd) in which the command was run.457458[More info.](environment.md#current-directory)459460### result.durationMs461462Type: `number`463464Duration of the subprocess, in milliseconds.465466[More info.](debugging.md#duration)467468### result.failed469470Type: `boolean`471472Whether the subprocess failed to run.473474[More info.](errors.md#subprocess-failure)475476### result.timedOut477478Type: `boolean`479480Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.481482[More info.](termination.md#timeout)483484### result.isCanceled485486Type: `boolean`487488Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.489490[More info.](termination.md#canceling)491492### result.isMaxBuffer493494Type: `boolean`495496Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.497498[More info.](output.md#big-output)499500### result.isTerminated501502Type: `boolean`503504Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:505- The current process.506- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).507508[More info.](termination.md#signal-name-and-description)509510### result.exitCode511512Type: `number | undefined`513514The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.515516This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).517518[More info.](errors.md#exit-code)519520### result.signal521522Type: `string | undefined`523524The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:525- The current process.526- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).527528If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.529530[More info.](termination.md#signal-name-and-description)531532### result.signalDescription533534Type: `string | undefined`535536A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.537538If 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.539540[More info.](termination.md#signal-name-and-description)541542## ExecaError543## ExecaSyncError544545Type: `Error`546547Exception thrown when the subprocess [fails](errors.md#subprocess-failure).548549This has the same shape as [successful results](#result), with the following additional properties.550551[More info.](errors.md)552553### error.message554555Type: `string`556557Error message when the subprocess [failed](errors.md#subprocess-failure) to run.558559[More info.](errors.md#error-message)560561### error.shortMessage562563Type: `string`564565This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).566567[More info.](errors.md#error-message)568569### error.originalMessage570571Type: `string | undefined`572573Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.574575[More info.](errors.md#error-message)576577### error.cause578579Type: `unknown | undefined`580581Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).582583This is usually an `Error` instance.584585[More info.](termination.md#error-message-and-stack-trace)586587### error.code588589Type: `string | undefined`590591Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.592593## Options594595Type: `object`596597This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).598599The 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).600601### options.preferLocal602603Type: `boolean`\604Default: `true` with [`$`](#file-arguments-options), `false` otherwise605606Prefer locally installed binaries when looking for a binary to execute.607608[More info.](environment.md#local-binaries)609610### options.localDir611612Type: `string | URL`\613Default: [`cwd`](#optionscwd) option614615Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.616617[More info.](environment.md#local-binaries)618619### options.node620621Type: `boolean`\622Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise623624If `true`, runs with Node.js. The first argument must be a Node.js file.625626[More info.](node.md)627628### options.nodeOptions629630Type: `string[]`\631Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)632633List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).634635Requires the [`node`](#optionsnode) option to be `true`.636637[More info.](node.md#nodejs-cli-flags)638639### options.nodePath640641Type: `string | URL`\642Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)643644Path to the Node.js executable.645646Requires the [`node`](#optionsnode) option to be `true`.647648[More info.](node.md#nodejs-version)649650### options.shell651652Type: `boolean | string | URL`\653Default: `false`654655If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).656657Uses [`/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.658659We [recommend against](shell.md#avoiding-shells) using this option.660661[More info.](shell.md)662663### options.cwd664665Type: `string | URL`\666Default: `process.cwd()`667668Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.669670This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.671672[More info.](environment.md#current-directory)673674### options.env675676Type: `object`\677Default: [`process.env`](https://nodejs.org/api/process.html#processenv)678679[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).680681Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).682683[More info.](input.md#environment-variables)684685### options.extendEnv686687Type: `boolean`\688Default: `true`689690If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).691If `false`, only the `env` option is used, not `process.env`.692693[More info.](input.md#environment-variables)694695### options.input696697Type: `string | Uint8Array | stream.Readable`698699Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).700701See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.702703[More info.](input.md#string-input)704705### options.inputFile706707Type: `string | URL`708709Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).710711See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.712713[More info.](input.md#file-input)714715### options.stdin716717Type: `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)\718Default: `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise719720How 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).721722This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.723724More info on [available values](input.md), [streaming](streams.md) and [transforms](transform.md).725726### options.stdout727728Type: `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)\729Default: `pipe`730731How 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).732733This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.734735More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).736737### options.stderr738739Type: `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)\740Default: `pipe`741742How 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).743744This can be an [array of values](output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.745746More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).747748### options.stdio749750Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\751Default: `pipe`752753Like 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'}`.754755A single string can be used [as a shortcut](output.md#shortcut).756757The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).758759More info on [available values](output.md), [streaming](streams.md) and [transforms](transform.md).760761### options.all762763Type: `boolean`\764Default: `false`765766Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.767768[More info.](output.md#interleaved-output)769770### options.encoding771772Type: `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\773Default: `'utf8'`774775If 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).776777If it outputs binary data instead, this should be either:778- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).779- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.780781The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).782783[More info.](binary.md)784785### options.lines786787Type: `boolean`\788Default: `false`789790Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.791792This cannot be used if the [`encoding`](#optionsencoding) option is [binary](binary.md#binary-output).793794By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).795796[More info.](lines.md#simple-splitting)797798### options.stripFinalNewline799800Type: `boolean`\801Default: `true`802803Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.804805If the [`lines`](#optionslines) option is true, this applies to each output line instead.806807By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).808809[More info.](lines.md#newlines)810811### options.maxBuffer812813Type: `number`\814Default: `100_000_000`815816Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).817818By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).819820[More info.](output.md#big-output)821822### options.buffer823824Type: `boolean`\825Default: `true`826827When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.828829By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).830831[More info.](output.md#low-memory)832833### options.ipc834835Type: `boolean`\836Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise837838Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).839840[More info.](ipc.md)841842### options.serialization843844Type: `'json' | 'advanced'`\845Default: `'advanced'`846847Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.848849[More info.](ipc.md#message-type)850851### options.verbose852853Type: `'none' | 'short' | 'full'`\854Default: `'none'`855856If `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.857858If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.859860By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](output.md#stdoutstderr-specific-options).861862[More info.](debugging.md#verbose-mode)863864### options.reject865866Type: `boolean`\867Default: `true`868869Setting this to `false` resolves the [result's promise](#subprocess) with the [error](#execaerror) instead of rejecting it.870871[More info.](errors.md#preventing-exceptions)872873### options.timeout874875Type: `number`\876Default: `0`877878If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.879880On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.881882[More info.](termination.md#timeout)883884### options.cancelSignal885886Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)887888You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).889890When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.891892[More info.](termination.md#canceling)893894### options.forceKillAfterDelay895896Type: `number | false`\897Default: `5000`898899If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).900901[More info.](termination.md#forceful-termination)902903### options.killSignal904905Type: `string | number`\906Default: `'SIGTERM'`907908Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.909910This can be either a name (like [`'SIGTERM'`](termination.md#sigterm)) or a number (like `9`).911912[More info.](termination.md#default-signal)913914### options.detached915916Type: `boolean`\917Default: `false`918919Run the subprocess independently from the current process.920921[More info.](environment.md#background-subprocess)922923### options.cleanup924925Type: `boolean`\926Default: `true`927928Kill the subprocess when the current process exits.929930[More info.](termination.md#current-process-exit)931932### options.uid933934Type: `number`\935Default: current user identifier936937Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.938939[More info.](windows.md#uid-and-gid)940941### options.gid942943Type: `number`\944Default: current group identifier945946Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.947948[More info.](windows.md#uid-and-gid)949950### options.argv0951952Type: `string`\953Default: file being executed954955Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.956957### options.windowsHide958959Type: `boolean`\960Default: `true`961962On Windows, do not create a new console window.963964[More info.](windows.md#console-window)965966### options.windowsVerbatimArguments967968Type: `boolean`\969Default: `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise970971If `false`, escapes the command arguments on Windows.972973[More info.](windows.md#cmdexe-escaping)974975## Transform options976977A transform or an [array of transforms](transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.978979A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.980981[More info.](transform.md)982983### transformOptions.transform984985Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`986987Map or [filter](transform.md#filtering) the [input](input.md) or [output](output.md) of the subprocess.988989More info [here](transform.md#summary) and [there](transform.md#sharing-state).990991### transformOptions.final992993Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`994995Create additional lines after the last one.996997[More info.](transform.md#finalizing)998999### transformOptions.binary10001001Type: `boolean`\1002Default: `false`10031004If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.10051006[More info.](binary.md#transforms)10071008### transformOptions.preserveNewlines10091010Type: `boolean`\1011Default: `false`10121013If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.10141015[More info.](lines.md#transforms)10161017### transformOptions.objectMode10181019Type: `boolean`\1020Default: `false`10211022If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.10231024[More info.](transform.md#object-mode)10251026<hr>10271028[**Previous**: 🔍 Differences with Bash and zx](bash.md)\1029[**Top**: Table of contents](../readme.md#documentation)
modified:docs/bash.md+1 added
858 unmodified lines
859[More info.](termination.md#inter-process-termination)860861<hr>862863[**Next**: 📔 API reference](api.md)\864[**Previous**: 📎 Windows](windows.md)\865[**Top**: Table of contents](../readme.md#documentation)
modified:docs/binary.md+6 added-6 removed
modified:docs/debugging.md+8 added-8 removed
modified:docs/environment.md+5 added-5 removed
6 unmodified lines
7# 🌐 Environment89## Current directory1011The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](../readme.md#optionscwd) option.11The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](api.md#optionscwd) option.1213```js14import {execa} from 'execa';1516await execa({cwd: '/path/to/cwd'})`npm run build`;17```1819And be retrieved with the [`result.cwd`](../readme.md#resultcwd) property.19And be retrieved with the [`result.cwd`](api.md#resultcwd) property.2021```js22const {cwd} = await execa`npm run build`;23```
9 unmodified lines
33```js34await execa('./node_modules/.bin/eslint');35```3637The [`preferLocal`](../readme.md#optionspreferlocal) option can be used to execute those local binaries.37The [`preferLocal`](api.md#optionspreferlocal) option can be used to execute those local binaries.3839```js40await execa('eslint', {preferLocal: true});41```4243Those are searched in the current or any parent directory. The [`localDir`](../readme.md#optionslocaldir) option can select a different directory.43Those are searched in the current or any parent directory. The [`localDir`](api.md#optionslocaldir) option can select a different directory.4445```js46await execa('eslint', {preferLocal: true, localDir: '/path/to/dir'});47```
11 unmodified lines
59```6061## Background subprocess6263When the [`detached`](../readme.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.63When the [`detached`](api.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.6465Specific behavior depends on the platform. [More info.](https://nodejs.org/api/child_process.html#child_process_options_detached)6667```js
8 unmodified lines
modified:docs/errors.md+11 added-11 removed
6 unmodified lines
7# ❌ Errors89## Subprocess failure1011When the subprocess fails, the promise returned by [`execa()`](../readme.md#execafile-arguments-options) is rejected with an [`ExecaError`](../readme.md#execaerror) instance. The `error` has the same shape as successful [results](../readme.md#result), with a few additional [error-specific fields](../readme.md#execaerror). [`error.failed`](../readme.md#resultfailed) is always `true`.11When the subprocess fails, the promise returned by [`execa()`](api.md#execafile-arguments-options) is rejected with an [`ExecaError`](api.md#execaerror) instance. The `error` has the same shape as successful [results](api.md#result), with a few additional [error-specific fields](api.md#execaerror). [`error.failed`](api.md#resultfailed) is always `true`.1213```js14import {execa, ExecaError} from 'execa';15
8 unmodified lines
24```2526## Preventing exceptions2728When the [`reject`](../readme.md#optionsreject) option is `false`, the `error` is returned instead.28When the [`reject`](api.md#optionsreject) option is `false`, the `error` is returned instead.2930```js31const resultOrError = await execa`npm run build`;32if (resultOrError.failed) {
2 unmodified lines
35```3637## Exit code3839The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](../readme.md#resultexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).39The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](api.md#resultexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).4041```js42try {43 await execa`npm run build`;
5 unmodified lines
4950## Failure reason5152The subprocess can fail for other reasons. Some of them can be detected using a specific boolean property:53- [`error.timedOut`](../readme.md#resulttimedout): [`timeout`](termination.md#timeout) option.54- [`error.isCanceled`](../readme.md#resultiscanceled): [`cancelSignal`](termination.md#canceling) option.55- [`error.isMaxBuffer`](../readme.md#resultismaxbuffer): [`maxBuffer`](output.md#big-output) option.56- [`error.isTerminated`](../readme.md#resultisterminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.53- [`error.timedOut`](api.md#resulttimedout): [`timeout`](termination.md#timeout) option.54- [`error.isCanceled`](api.md#resultiscanceled): [`cancelSignal`](termination.md#canceling) option.55- [`error.isMaxBuffer`](api.md#resultismaxbuffer): [`maxBuffer`](output.md#big-output) option.56- [`error.isTerminated`](api.md#resultisterminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.5758Otherwise, the subprocess failed because either:59- An exception was thrown in a [stream](streams.md) or [transform](transform.md).60- The command's executable file was not found.61- An invalid [option](../readme.md#options) was passed.61- An invalid [option](api.md#options) was passed.62- There was not enough memory or too many subprocesses.6364```js65try {
8 unmodified lines
74```7576## Error message7778For better [debugging](debugging.md), [`error.message`](../readme.md#errormessage) includes both:78For better [debugging](debugging.md), [`error.message`](api.md#errormessage) includes both:79- The command and the [reason it failed](#failure-reason).80- Its [`stdout`, `stderr`](output.md#stdout-and-stderr) and [other file descriptors'](output.md#additional-file-descriptors) output, separated with newlines and not [interleaved](output.md#interleaved-output).8182[`error.shortMessage`](../readme.md#errorshortmessage) is the same but without `stdout`/`stderr`.82[`error.shortMessage`](api.md#errorshortmessage) is the same but without `stdout`/`stderr`.8384[`error.originalMessage`](../readme.md#errororiginalmessage) is the same but also without the command. This exists only in specific instances, such as when calling [`subprocess.kill(error)`](termination.md#error-message-and-stack-trace), using the [`cancelSignal`](termination.md#canceling) option, passing an invalid command or [option](../readme.md#options), or throwing an exception in a [stream](streams.md) or [transform](transform.md).84[`error.originalMessage`](api.md#errororiginalmessage) is the same but also without the command. This exists only in specific instances, such as when calling [`subprocess.kill(error)`](termination.md#error-message-and-stack-trace), using the [`cancelSignal`](termination.md#canceling) option, passing an invalid command or [option](api.md#options), or throwing an exception in a [stream](streams.md) or [transform](transform.md).8586```js87try {88 await execa`npm run build`;
33 unmodified lines
modified:docs/escaping.md+2 added-2 removed
34 unmodified lines
35await execa(command, commandArguments);36await execa`${command} ${commandArguments}`;37```3839However, [`execaCommand()`](../readme.md#execacommandcommand-options) must be used instead if:39However, [`execaCommand()`](api.md#execacommandcommand-options) must be used instead if:40- _Both_ the file and its arguments are user-defined41- _And_ those are supplied as a single string4243This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.
11 unmodified lines
55```5657## Shells5859[Shells](shell.md) ([Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), [cmd.exe](https://en.wikipedia.org/wiki/Cmd.exe), etc.) are not used unless the [`shell`](../readme.md#optionsshell) option is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.59[Shells](shell.md) ([Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), [cmd.exe](https://en.wikipedia.org/wiki/Cmd.exe), etc.) are not used unless the [`shell`](api.md#optionsshell) option is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.6061If you do set the `shell` option, arguments will not be automatically escaped anymore. Instead, they will be concatenated as a single string using spaces as delimiters.6263```js
24 unmodified lines
modified:docs/execution.md+13 added-13 removed
14 unmodified lines
15```1617## Template string syntax1819All [available methods](../readme.md#methods) can use either the [array syntax](#array-syntax) or the template string syntax, which are equivalent.19All [available methods](api.md#methods) can use either the [array syntax](#array-syntax) or the template string syntax, which are equivalent.2021```js22await execa`npm run build`;23```
43 unmodified lines
67```6869## Options7071[Options](../readme.md#options) can be passed to influence the execution's behavior.71[Options](api.md#options) can be passed to influence the execution's behavior.7273### Array syntax7475```js
18 unmodified lines
94## Return value9596### Subprocess9798The subprocess is returned as soon as it is spawned. It is a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with [additional methods and properties](../readme.md#subprocess).98The subprocess is returned as soon as it is spawned. It is a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with [additional methods and properties](api.md#subprocess).99100```js101const subprocess = execa`npm run build`;102console.log(subprocess.pid);103```104105### Result106107The subprocess is also a `Promise` that resolves with the [`result`](../readme.md#result).107The subprocess is also a `Promise` that resolves with the [`result`](api.md#result).108109```js110const {stdout} = await execa`npm run build`;111```112113### Synchronous execution114115[Every method](../readme.md#methods) can be called synchronously by appending `Sync` to the method's name. The [`result`](../readme.md#result) is returned without needing to `await`. The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.115[Every method](api.md#methods) can be called synchronously by appending `Sync` to the method's name. The [`result`](api.md#result) is returned without needing to `await`. The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.116117```js118import {execaSync} from 'execa';119120const {stdout} = execaSync`npm run build`;121```122123Synchronous execution is generally discouraged as it holds the CPU and prevents parallelization. Also, the following features cannot be used:124- Streams: [`subprocess.stdin`](../readme.md#subprocessstdin), [`subprocess.stdout`](../readme.md#subprocessstdout), [`subprocess.stderr`](../readme.md#subprocessstderr), [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions), [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions).125- The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and [`stdio`](../readme.md#optionsstdio) options cannot be [`'overlapped'`](../readme.md#optionsstdout), an [async iterable](lines.md#progressive-splitting), an async [transform](transform.md), a [`Duplex`](transform.md#duplextransform-streams), nor a [web stream](streams.md#web-streams). Node.js streams can be passed but only if either they [have a file descriptor](streams.md#file-descriptors), or the [`input`](../readme.md#optionsinput) option is used.126- Signal termination: [`subprocess.kill()`](../readme.md#subprocesskillerror), [`subprocess.pid`](../readme.md#subprocesspid), [`cleanup`](../readme.md#optionscleanup) option, [`cancelSignal`](../readme.md#optionscancelsignal) option, [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option.127- Piping multiple subprocesses: [`subprocess.pipe()`](../readme.md#subprocesspipefile-arguments-options).124- Streams: [`subprocess.stdin`](api.md#subprocessstdin), [`subprocess.stdout`](api.md#subprocessstdout), [`subprocess.stderr`](api.md#subprocessstderr), [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions), [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions).125- The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and [`stdio`](api.md#optionsstdio) options cannot be [`'overlapped'`](api.md#optionsstdout), an [async iterable](lines.md#progressive-splitting), an async [transform](transform.md), a [`Duplex`](transform.md#duplextransform-streams), nor a [web stream](streams.md#web-streams). Node.js streams can be passed but only if either they [have a file descriptor](streams.md#file-descriptors), or the [`input`](api.md#optionsinput) option is used.126- Signal termination: [`subprocess.kill()`](api.md#subprocesskillerror), [`subprocess.pid`](api.md#subprocesspid), [`cleanup`](api.md#optionscleanup) option, [`cancelSignal`](api.md#optionscancelsignal) option, [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option.127- Piping multiple subprocesses: [`subprocess.pipe()`](api.md#subprocesspipefile-arguments-options).128- [`subprocess.iterable()`](lines.md#progressive-splitting).129- [`ipc`](../readme.md#optionsipc) and [`serialization`](../readme.md#optionsserialization) options.130- [`result.all`](../readme.md#resultall) is not interleaved.131- [`detached`](../readme.md#optionsdetached) option.132- The [`maxBuffer`](../readme.md#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](../readme.md#optionslines) nor [objects](transform.md#object-mode). Also, it ignores transforms and the [`encoding`](../readme.md#optionsencoding) option.129- [`ipc`](api.md#optionsipc) and [`serialization`](api.md#optionsserialization) options.130- [`result.all`](api.md#resultall) is not interleaved.131- [`detached`](api.md#optionsdetached) option.132- The [`maxBuffer`](api.md#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](api.md#optionslines) nor [objects](transform.md#object-mode). Also, it ignores transforms and the [`encoding`](api.md#optionsencoding) option.133134<hr>135136[**Next**: 💬 Escaping/quoting](escaping.md)\
1 unmodified line
modified:docs/input.md+3 added-3 removed
50 unmodified lines
51## String input5253Alternatively, input can be provided to [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). Unlike [command arguments](#command-arguments) and [environment variables](#environment-variables) which have [size](https://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument) [limits](https://stackoverflow.com/questions/1078031/what-is-the-maximum-size-of-a-linux-environment-variable-value), `stdin` works when the input is big. Also, the input can be redirected from the [terminal](#terminal-input), a [file](#file-input), another [subprocess](pipe.md) or a [stream](streams.md#manual-streaming). Finally, this is required when the input might contain [null bytes](https://en.wikipedia.org/wiki/Null_character), for example when it might be [binary](binary.md#binary-input).5455If the input is already available as a string, it can be passed directly to the [`input`](../readme.md#optionsinput) option.55If the input is already available as a string, it can be passed directly to the [`input`](api.md#optionsinput) option.5657```js58await execa({input: 'stdinInput'})`npm run scaffold`;59```6061The [`stdin`](../readme.md#optionsstdin) option can also be used, although the string must be wrapped in two arrays for [syntax reasons](output.md#multiple-targets).61The [`stdin`](api.md#optionsstdin) option can also be used, although the string must be wrapped in two arrays for [syntax reasons](output.md#multiple-targets).6263```js64await execa({stdin: [['stdinInput']]})`npm run scaffold`;65```
25 unmodified lines
91```9293## Additional file descriptors9495The [`stdio`](../readme.md#optionsstdio) option can be used to pass some input to any [file descriptor](https://en.wikipedia.org/wiki/File_descriptor), as opposed to only [`stdin`](../readme.md#optionsstdin).95The [`stdio`](api.md#optionsstdio) option can be used to pass some input to any [file descriptor](https://en.wikipedia.org/wiki/File_descriptor), as opposed to only [`stdin`](api.md#optionsstdin).9697```js98// Pass input to the file descriptor number 399await execa({
9 unmodified lines
modified:docs/ipc.md+3 added-3 removed
6 unmodified lines
7# 📞 Inter-process communication89## Exchanging messages1011When the [`ipc`](../readme.md#optionsipc) option is `true`, the current process and subprocess can exchange messages. This only works if the subprocess is a Node.js file.11When the [`ipc`](api.md#optionsipc) option is `true`, the current process and subprocess can exchange messages. This only works if the subprocess is a Node.js file.1213The `ipc` option defaults to `true` when using [`execaNode()`](node.md#run-nodejs-files) or the [`node`](node.md#run-nodejs-files) option.1415The current process sends messages with [`subprocess.send(message)`](../readme.md#subprocesssendmessage) and receives them with [`subprocess.on('message', (message) => {})`](../readme.md#subprocessonmessage-message--void). The subprocess sends messages with [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) and [`process.on('message', (message) => {})`](https://nodejs.org/api/process.html#event-message).15The current process sends messages with [`subprocess.send(message)`](api.md#subprocesssendmessage) and receives them with [`subprocess.on('message', (message) => {})`](api.md#subprocessonmessage-message--void). The subprocess sends messages with [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) and [`process.on('message', (message) => {})`](https://nodejs.org/api/process.html#event-message).1617More info on [sending](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [receiving](https://nodejs.org/api/child_process.html#event-message) messages.1819```js
20 unmodified lines
40## Message type4142By default, messages are serialized using [`structuredClone()`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). This supports most types including objects, arrays, `Error`, `Date`, `RegExp`, `Map`, `Set`, `bigint`, `Uint8Array`, and circular references. This throws when passing functions, symbols or promises (including inside an object or array).4344To limit messages to JSON instead, the [`serialization`](../readme.md#optionsserialization) option can be set to `'json'`.44To limit messages to JSON instead, the [`serialization`](api.md#optionsserialization) option can be set to `'json'`.4546```js47const subprocess = execaNode({serialization: 'json'})`child.js`;48```
6 unmodified lines
modified:docs/lines.md+11 added-11 removed
6 unmodified lines
7# 📃 Text lines89## Simple splitting1011If the [`lines`](../readme.md#optionslines) option is `true`, the output is split into lines, as an array of strings.11If the [`lines`](api.md#optionslines) option is `true`, the output is split into lines, as an array of strings.1213```js14import {execa} from 'execa';15
4 unmodified lines
20## Iteration2122### Progressive splitting2324The subprocess' return value is an [async iterable](../readme.md#subprocesssymbolasynciterator). It iterates over the output's lines while the subprocess is still running.24The subprocess' return value is an [async iterable](api.md#subprocesssymbolasynciterator). It iterates over the output's lines while the subprocess is still running.2526```js27for await (const line of execa`npm run build`) {28 if (line.includes('ERROR')) {
1 unmodified line
30 }31}32```3334Alternatively, [`subprocess.iterable()`](../readme.md#subprocessiterablereadableoptions) can be called to pass [iterable options](../readme.md#readableoptions).34Alternatively, [`subprocess.iterable()`](api.md#subprocessiterablereadableoptions) can be called to pass [iterable options](api.md#readableoptions).3536The iteration waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](../readme.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).36The iteration waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](api.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).3738```js39for await (const line of execa`npm run build`.iterable())) {40 /* ... */
1 unmodified line
42```4344### Stdout/stderr4546By default, the subprocess' [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) is used. The [`from`](../readme.md#readableoptionsfrom) iterable option can select a different file descriptor, such as [`'stderr'`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), [`'all'`](output.md#interleaved-output) or [`'fd3'`](output.md#additional-file-descriptors).46By default, the subprocess' [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) is used. The [`from`](api.md#readableoptionsfrom) iterable option can select a different file descriptor, such as [`'stderr'`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), [`'all'`](output.md#interleaved-output) or [`'fd3'`](output.md#additional-file-descriptors).4748```js49for await (const stderrLine of execa`npm run build`.iterable({from: 'stderr'})) {50 /* ... */
3 unmodified lines
54## Newlines5556### Final newline5758The final newline is stripped from the output's last line, unless the [`stripFinalNewline`](../readme.md#optionsstripfinalnewline) option is `false`.58The final newline is stripped from the output's last line, unless the [`stripFinalNewline`](api.md#optionsstripfinalnewline) option is `false`.5960```js61const {stdout} = await execa({stripFinalNewline: false})`npm run build`;62console.log(stdout.endsWith('\n')); // true63```6465### Array of lines6667When using the [`lines`](#simple-splitting) option, newlines are stripped from each line, unless the [`stripFinalNewline`](../readme.md#optionsstripfinalnewline) option is `false`.67When using the [`lines`](#simple-splitting) option, newlines are stripped from each line, unless the [`stripFinalNewline`](api.md#optionsstripfinalnewline) option is `false`.6869```js70// Each line now ends with '\n'.71// The last `line` might or might not end with '\n', depending on the output.
2 unmodified lines
74```7576### Iterable7778When [iterating](#progressive-splitting) over lines, newlines are stripped from each line, unless the [`preserveNewlines`](../readme.md#readableoptionspreservenewlines) iterable option is `true`.78When [iterating](#progressive-splitting) over lines, newlines are stripped from each line, unless the [`preserveNewlines`](api.md#readableoptionspreservenewlines) iterable option is `true`.7980This option can also be used with [streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions) or [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions), providing the [`binary`](binary.md#streams) option is `false`.80This option can also be used with [streams produced](streams.md#converting-a-subprocess-to-a-stream) by [`subprocess.readable()`](api.md#subprocessreadablereadableoptions) or [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions), providing the [`binary`](binary.md#streams) option is `false`.8182```js83// `line` now ends with '\n'.84// The last `line` might or might not end with '\n', depending on the output.
3 unmodified lines
88```8990### Transforms9192When using [transforms](transform.md), newlines are stripped from each `line` argument, unless the [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) transform option is `true`.92When using [transforms](transform.md), newlines are stripped from each `line` argument, unless the [`preserveNewlines`](api.md#transformoptionspreservenewlines) transform option is `true`.9394```js95// `line` now ends with '\n'.96// The last `line` might or might not end with '\n', depending on the output.
23 unmodified lines
120121await execa({stdout: transform})`npm run build`;122```123124However, if the [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) transform option is `true`, multiple `yield`s produce a single line instead.124However, if the [`preserveNewlines`](api.md#transformoptionspreservenewlines) transform option is `true`, multiple `yield`s produce a single line instead.125126```js127const transform = function * (line) {128 yield 'Important note: ';
16 unmodified lines
modified:docs/node.md+1 added-1 removed
24 unmodified lines
25```2627## Node.js version2829[`get-node`](https://github.com/ehmicky/get-node) and the [`nodePath`](../readme.md#optionsnodepath) option can be used to run a specific Node.js version. Alternatively, [`nvexeca`](https://github.com/ehmicky/nvexeca) or [`nve`](https://github.com/ehmicky/nve) can be used.29[`get-node`](https://github.com/ehmicky/get-node) and the [`nodePath`](api.md#optionsnodepath) option can be used to run a specific Node.js version. Alternatively, [`nvexeca`](https://github.com/ehmicky/nvexeca) or [`nve`](https://github.com/ehmicky/nve) can be used.3031```js32import {execaNode} from 'execa';33import getNode from 'get-node';
10 unmodified lines
modified:docs/output.md+12 added-12 removed
6 unmodified lines
7# 📢 Output89## Stdout and stderr1011The [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options redirect the subprocess output. They default to `'pipe'`, which returns the output using [`result.stdout`](../readme.md#resultstdout) and [`result.stderr`](../readme.md#resultstderr).11The [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options redirect the subprocess output. They default to `'pipe'`, which returns the output using [`result.stdout`](api.md#resultstdout) and [`result.stderr`](api.md#resultstderr).1213```js14import {execa} from 'execa';15
36 unmodified lines
52```5354## Multiple targets5556The output can be redirected to multiple targets by setting the [`stdout`](../readme.md#optionsstdout) or [`stderr`](../readme.md#optionsstderr) option to an array of values. This also allows specifying multiple inputs with the [`stdin`](../readme.md#optionsstdin) option.56The output can be redirected to multiple targets by setting the [`stdout`](api.md#optionsstdout) or [`stderr`](api.md#optionsstderr) option to an array of values. This also allows specifying multiple inputs with the [`stdin`](api.md#optionsstdin) option.5758The following example redirects `stdout` to both the [terminal](#terminal-output) and an `output.txt` [file](#file-output), while also retrieving its value [programmatically](#stdout-and-stderr).5960```js
4 unmodified lines
65When combining [`'inherit'`](#terminal-output) with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.6667## Interleaved output6869If the [`all`](../readme.md#optionsall) option is `true`, [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) are combined:70- [`result.all`](../readme.md#resultall): [`result.stdout`](../readme.md#resultstdout) + [`result.stderr`](../readme.md#resultstderr)71- [`subprocess.all`](../readme.md#subprocessall): [`subprocess.stdout`](../readme.md#subprocessstdout) + [`subprocess.stderr`](../readme.md#subprocessstderr)69If the [`all`](api.md#optionsall) option is `true`, [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) are combined:70- [`result.all`](api.md#resultall): [`result.stdout`](api.md#resultstdout) + [`result.stderr`](api.md#resultstderr)71- [`subprocess.all`](api.md#subprocessall): [`subprocess.stdout`](api.md#subprocessstdout) + [`subprocess.stderr`](api.md#subprocessstderr)7273`stdout` and `stderr` are guaranteed to interleave. However, for performance reasons, the subprocess might buffer and merge multiple simultaneous writes to `stdout` or `stderr`. This can prevent proper interleaving.7475For example, this prints `1 3 2` instead of `1 2 3` because both `console.log()` are merged into a single write.
21 unmodified lines
97```9899## Stdout/stderr-specific options100101Some options are related to the subprocess output: [`verbose`](../readme.md#optionsverbose), [`lines`](../readme.md#optionslines), [`stripFinalNewline`](../readme.md#optionsstripfinalnewline), [`buffer`](../readme.md#optionsbuffer), [`maxBuffer`](../readme.md#optionsmaxbuffer). By default, those options apply to all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) ([`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), and [others](#additional-file-descriptors)). A plain object can be passed instead to apply them to only `stdout`, `stderr`, [`fd3`](#additional-file-descriptors), etc.101Some options are related to the subprocess output: [`verbose`](api.md#optionsverbose), [`lines`](api.md#optionslines), [`stripFinalNewline`](api.md#optionsstripfinalnewline), [`buffer`](api.md#optionsbuffer), [`maxBuffer`](api.md#optionsmaxbuffer). By default, those options apply to all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) ([`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)), and [others](#additional-file-descriptors)). A plain object can be passed instead to apply them to only `stdout`, `stderr`, [`fd3`](#additional-file-descriptors), etc.102103```js104// Same value for stdout and stderr105await execa({verbose: 'full'})`npm run build`;
3 unmodified lines
109```110111## Additional file descriptors112113The [`stdio`](../readme.md#optionsstdio) option is an array combining [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and any other file descriptor. It is useful when using additional [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) beyond the [standard ones](https://en.wikipedia.org/wiki/Standard_streams), either for [input](input.md#additional-file-descriptors) or output.113The [`stdio`](api.md#optionsstdio) option is an array combining [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and any other file descriptor. It is useful when using additional [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) beyond the [standard ones](https://en.wikipedia.org/wiki/Standard_streams), either for [input](input.md#additional-file-descriptors) or output.114115[`result.stdio`](../readme.md#resultstdio) can be used to retrieve some output from any file descriptor, as opposed to only [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr).115[`result.stdio`](api.md#resultstdio) can be used to retrieve some output from any file descriptor, as opposed to only [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr).116117```js118// Retrieve output from file descriptor number 3119const {stdio} = await execa({
3 unmodified lines
123```124125## Shortcut126127The [`stdio`](../readme.md#optionsstdio) option can also be a single value [`'pipe'`](#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore'`](#ignore-output) or [`'inherit'`](#terminal-output). This is a shortcut for setting that same value with the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options.127The [`stdio`](api.md#optionsstdio) option can also be a single value [`'pipe'`](#stdout-and-stderr), [`'overlapped'`](windows.md#asynchronous-io), [`'ignore'`](#ignore-output) or [`'inherit'`](#terminal-output). This is a shortcut for setting that same value with the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options.128129```js130await execa({stdio: 'ignore'})`npm run build`;131// Same as:
1 unmodified line
133```134135## Big output136137To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](../readme.md#optionsmaxbuffer) option. It defaults to 100MB.137To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.138139When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](../readme.md#resultismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](../readme.md#resultstdout) and [`error.stderr`](../readme.md#resultstderr).139When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#resultismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout) and [`error.stderr`](api.md#resultstderr).140141This is measured:142- By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).143- If the [`encoding`](binary.md#encoding) option is `'buffer'`: in bytes.
15 unmodified lines
159```160161## Low memory162163When the [`buffer`](../readme.md#optionsbuffer) option is `false`, [`result.stdout`](../readme.md#resultstdout), [`result.stderr`](../readme.md#resultstderr), [`result.all`](../readme.md#resultall) and [`result.stdio[*]`](../readme.md#resultstdio) properties are not set.163When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall) and [`result.stdio[*]`](api.md#resultstdio) properties are not set.164165This prevents high memory consumption when the output is big. However, the output must be either ignored, [redirected](#file-output) or [streamed](streams.md). If streamed, this should be done right away to avoid missing any data.166167<hr>
4 unmodified lines
modified:docs/pipe.md+7 added-7 removed
33 unmodified lines
34```3536## Options3738[Options](../readme.md#options) can be passed to either the source or the destination subprocess. Some [pipe-specific options](../readme.md#pipeoptions) can also be set by the destination subprocess.38[Options](api.md#options) can be passed to either the source or the destination subprocess. Some [pipe-specific options](api.md#pipeoptions) can also be set by the destination subprocess.3940```js41const {stdout} = await execa('npm', ['run', 'build'], subprocessOptions)42 .pipe('head', ['-n', '2'], subprocessOrPipeOptions);
11 unmodified lines
54```5556## Result5758When both subprocesses succeed, the [`result`](../readme.md#result) of the destination subprocess is returned. The [`result`](../readme.md#result) of the source subprocess is available in a [`result.pipedFrom`](../readme.md#resultpipedfrom) array.58When both subprocesses succeed, the [`result`](api.md#result) of the destination subprocess is returned. The [`result`](api.md#result) of the source subprocess is available in a [`result.pipedFrom`](api.md#resultpipedfrom) array.5960```js61const destinationResult = await execa`npm run build`62 .pipe`head -n 2`;
4 unmodified lines
67```6869## Errors7071When either subprocess fails, `subprocess.pipe()` is rejected with that subprocess' error. If the destination subprocess fails, [`error.pipedFrom`](../readme.md#resultpipedfrom) includes the source subprocess' result, which is useful for debugging.71When either subprocess fails, `subprocess.pipe()` is rejected with that subprocess' error. If the destination subprocess fails, [`error.pipedFrom`](api.md#resultpipedfrom) includes the source subprocess' result, which is useful for debugging.7273```js74try {75 await execa`npm run build`
42 unmodified lines
118```119120## Source file descriptor121122By default, the source's [`stdout`](../readme.md#subprocessstdout) is used, but this can be changed using the [`from`](../readme.md#pipeoptionsfrom) piping option.122By default, the source's [`stdout`](api.md#subprocessstdout) is used, but this can be changed using the [`from`](api.md#pipeoptionsfrom) piping option.123124```js125await execa`npm run build`126 .pipe({from: 'stderr'})`head -n 2`;127```128129## Destination file descriptor130131By default, the destination's [`stdin`](../readme.md#subprocessstdin) is used, but this can be changed using the [`to`](../readme.md#pipeoptionsto) piping option.131By default, the destination's [`stdin`](api.md#subprocessstdin) is used, but this can be changed using the [`to`](api.md#pipeoptionsto) piping option.132133```js134await execa`npm run build`135 .pipe({to: 'fd3'})`./log-remotely.js`;136```137138## Unpipe139140Piping can be stopped using the [`unpipeSignal`](../readme.md#pipeoptionsunpipesignal) piping option.140Piping can be stopped using the [`unpipeSignal`](api.md#pipeoptionsunpipesignal) piping option.141142The [`subprocess.pipe()`](../readme.md#subprocesspipefile-arguments-options) method will be rejected with a cancelation error. However, each subprocess will keep running.142The [`subprocess.pipe()`](api.md#subprocesspipefile-arguments-options) method will be rejected with a cancelation error. However, each subprocess will keep running.143144```js145const abortController = new AbortController();146
21 unmodified lines
modified:docs/scripts.md+2 added-2 removed
8 unmodified lines
9## Script files1011[Scripts](https://en.wikipedia.org/wiki/Shell_script) are Node.js files executing a series of commands. While those used to be written with a shell language like [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), libraries like Execa provide with a better, modern experience.1213Scripts use [`$`](../readme.md#file-arguments-options) instead of [`execa`](../readme.md#execafile-arguments-options). The only difference is that `$` includes script-friendly default options: [`stdin: 'inherit'`](input.md#terminal-input) and [`preferLocal: true`](environment.md#local-binaries).13Scripts use [`$`](api.md#file-arguments-options) instead of [`execa`](api.md#execafile-arguments-options). The only difference is that `$` includes script-friendly default options: [`stdin: 'inherit'`](input.md#terminal-input) and [`preferLocal: true`](environment.md#local-binaries).1415[More info about the difference between Execa, Bash and zx.](bash.md)1617```js
17 unmodified lines
35```3637## Template string syntax3839Just like [`execa`](../readme.md#execafile-arguments-options), [`$`](../readme.md#file-arguments-options) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).39Just like [`execa`](api.md#execafile-arguments-options), [`$`](api.md#file-arguments-options) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).4041Conversely, the template string syntax can be used outside of script files: `$` is not required to use that syntax. For example, `execa` [can use it too](execution.md#template-string-syntax).4243```js
11 unmodified lines
modified:docs/shell.md+1 added-1 removed
21 unmodified lines
22```2324## OS-specific shell2526When the [`shell`](../readme.md#optionsshell) option is `true`, `sh` is used on Unix and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows.26When the [`shell`](api.md#optionsshell) option is `true`, `sh` is used on Unix and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows.2728`sh` and `cmd.exe` syntaxes are very different. Therefore, this is usually not useful.2930```js
8 unmodified lines
modified:docs/streams.md+7 added-7 removed
32 unmodified lines
33```3435### File descriptors3637When passing a Node.js stream to the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) or [`stderr`](../readme.md#optionsstderr) option, that stream must have an underlying file or socket, such as the streams created by the [`fs`](https://nodejs.org/api/fs.html#filehandlecreatereadstreamoptions), [`net`](https://nodejs.org/api/net.html#new-netsocketoptions) or [`http`](https://nodejs.org/api/http.html#class-httpincomingmessage) core modules. Otherwise the following error is thrown.37When passing a Node.js stream to the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) or [`stderr`](api.md#optionsstderr) option, that stream must have an underlying file or socket, such as the streams created by the [`fs`](https://nodejs.org/api/fs.html#filehandlecreatereadstreamoptions), [`net`](https://nodejs.org/api/net.html#new-netsocketoptions) or [`http`](https://nodejs.org/api/http.html#class-httpincomingmessage) core modules. Otherwise the following error is thrown.3839```40TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.41```4243This limitation can be worked around by either:44- Using the [`input`](../readme.md#optionsinput) option instead of the [`stdin`](../readme.md#optionsstdin) option.44- Using the [`input`](api.md#optionsinput) option instead of the [`stdin`](api.md#optionsstdin) option.45- Passing a [web stream](#web-streams).46- Passing [`[nodeStream, 'pipe']`](output.md#multiple-targets) instead of `nodeStream`.4748## Web streams
18 unmodified lines
67```6869## Manual streaming7071[`subprocess.stdin`](../readme.md#subprocessstdin) is a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) stream and [`subprocess.stdout`](../readme.md#subprocessstdout)/[`subprocess.stderr`](../readme.md#subprocessstderr)/[`subprocess.all`](../readme.md#subprocessall) are Node.js [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) streams.71[`subprocess.stdin`](api.md#subprocessstdin) is a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) stream and [`subprocess.stdout`](api.md#subprocessstdout)/[`subprocess.stderr`](api.md#subprocessstderr)/[`subprocess.all`](api.md#subprocessall) are Node.js [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) streams.7273They can be used to stream input/output manually. This is intended for advanced situations. In most cases, the following simpler solutions can be used instead:74- [`result.stdout`](output.md#stdout-and-stderr), [`result.stderr`](output.md#stdout-and-stderr) or [`result.stdio`](output.md#additional-file-descriptors).75- The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) or [`stdio`](../readme.md#optionsstdio) options.75- The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) or [`stdio`](api.md#optionsstdio) options.76- [`subprocess.iterable()`](lines.md#progressive-splitting).77- [`subprocess.pipe()`](pipe.md).7879## Converting a subprocess to a stream8081### Convert8283The [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions) methods convert the subprocess to a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable), [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) and [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream.83The [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions) methods convert the subprocess to a Node.js [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable), [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) and [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream.8485This is useful when using a library or API that expects Node.js streams as arguments. In every other situation, the simpler solutions described [above](#manual-streaming) can be used instead.8687```js
5 unmodified lines
93```9495### Different file descriptor9697By default, [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions) methods use [`stdin`](../readme.md#subprocessstdin) and [`stdout`](../readme.md#subprocessstdout). This can be changed using the [`from`](../readme.md#readableoptionsfrom) and [`to`](../readme.md#writableoptionsto) options.97By default, [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) and [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions) methods use [`stdin`](api.md#subprocessstdin) and [`stdout`](api.md#subprocessstdout). This can be changed using the [`from`](api.md#readableoptionsfrom) and [`to`](api.md#writableoptionsto) options.9899```js100const readable = execa`npm run scaffold`.readable({from: 'stderr'});101
3 unmodified lines
105```106107### Error handling108109When using [`subprocess.readable()`](../readme.md#subprocessreadablereadableoptions), [`subprocess.writable()`](../readme.md#subprocesswritablewritableoptions) or [`subprocess.duplex()`](../readme.md#subprocessduplexduplexoptions), the stream waits for the subprocess to end, and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](errors.md). This differs from [`subprocess.stdin`](../readme.md#subprocessstdin), [`subprocess.stdout`](../readme.md#subprocessstdout) and [`subprocess.stderr`](../readme.md#subprocessstderr)'s behavior.109When using [`subprocess.readable()`](api.md#subprocessreadablereadableoptions), [`subprocess.writable()`](api.md#subprocesswritablewritableoptions) or [`subprocess.duplex()`](api.md#subprocessduplexduplexoptions), the stream waits for the subprocess to end, and emits an [`error`](https://nodejs.org/api/stream.html#event-error) event if the subprocess [fails](errors.md). This differs from [`subprocess.stdin`](api.md#subprocessstdin), [`subprocess.stdout`](api.md#subprocessstdout) and [`subprocess.stderr`](api.md#subprocessstderr)'s behavior.110111This means you do not need to `await` the subprocess' [promise](execution.md#result). On the other hand, you (or the library using the stream) do need to both consume the stream, and handle its `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options), [`await pipeline(..., stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) or [`await text(stream)`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) which throw an exception when the stream errors.112113<hr>
4 unmodified lines
modified:docs/termination.md+14 added-14 removed
6 unmodified lines
7# 🏁 Termination89## Canceling1011The [`cancelSignal`](../readme.md#optionscancelsignal) option can be used to cancel a subprocess. When [`abortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), a [`SIGTERM` signal](#default-signal) is sent to the subprocess.11The [`cancelSignal`](api.md#optionscancelsignal) option can be used to cancel a subprocess. When [`abortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), a [`SIGTERM` signal](#default-signal) is sent to the subprocess.1213```js14import {execa} from 'execa';15
15 unmodified lines
31```3233## Timeout3435If the subprocess lasts longer than the [`timeout`](../readme.md#optionstimeout) option, a [`SIGTERM` signal](#default-signal) is sent to it.35If the subprocess lasts longer than the [`timeout`](api.md#optionstimeout) option, a [`SIGTERM` signal](#default-signal) is sent to it.3637```js38try {39 await execa({timeout: 5000})`npm run build`;
8 unmodified lines
4849## Current process exit5051If the current process exits, the subprocess is automatically [terminated](#default-signal) unless either:52- The [`cleanup`](../readme.md#optionscleanup) option is `false`.53- The subprocess is run in the background using the [`detached`](../readme.md#optionsdetached) option.52- The [`cleanup`](api.md#optionscleanup) option is `false`.53- The subprocess is run in the background using the [`detached`](api.md#optionsdetached) option.54- The current process was terminated abruptly, for example, with [`SIGKILL`](#sigkill) as opposed to [`SIGTERM`](#sigterm) or a successful exit.5556## Signal termination5758[`subprocess.kill()`](../readme.md#subprocesskillsignal-error) sends a [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) to the subprocess. This is an inter-process message handled by the OS. Most (but [not all](https://github.com/ehmicky/human-signals#action)) signals terminate the subprocess.58[`subprocess.kill()`](api.md#subprocesskillsignal-error) sends a [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) to the subprocess. This is an inter-process message handled by the OS. Most (but [not all](https://github.com/ehmicky/human-signals#action)) signals terminate the subprocess.5960[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)6162### SIGTERM
29 unmodified lines
92Other signals can be passed as argument. However, most other signals do not fully [work on Windows](https://github.com/ehmicky/cross-platform-node-guide/blob/main/docs/6_networking_ipc/signals.md#cross-platform-signals).9394### Default signal9596The [`killSignal`](../readme.md#optionskillsignal) option sets the default signal used by [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) and the following options: [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) and [`cleanup`](#current-process-exit). It is [`SIGTERM`](#sigterm) by default.96The [`killSignal`](api.md#optionskillsignal) option sets the default signal used by [`subprocess.kill()`](api.md#subprocesskillsignal-error) and the following options: [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) and [`cleanup`](#current-process-exit). It is [`SIGTERM`](#sigterm) by default.9798```js99const subprocess = execa({killSignal: 'SIGKILL'})`npm run build`;100subprocess.kill(); // Forceful termination101```102103### Signal name and description104105When a subprocess was terminated by a signal, [`error.isTerminated`](../readme.md#resultisterminated) is `true`.105When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#resultisterminated) is `true`.106107Also, [`error.signal`](../readme.md#resultsignal) and [`error.signalDescription`](../readme.md#resultsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).107Also, [`error.signal`](api.md#resultsignal) and [`error.signalDescription`](api.md#resultsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).108109```js110try {111 await execa`npm run build`;
10 unmodified lines
122## Forceful termination123124If the subprocess is terminated but does not exit, [`SIGKILL`](#sigkill) is automatically sent to forcefully terminate it.125126The grace period is set by the [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option, which is 5 seconds by default. This feature can be disabled with `false`.126The grace period is set by the [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option, which is 5 seconds by default. This feature can be disabled with `false`.127128This works when the subprocess is terminated by either:129- Calling [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) with no arguments.129- Calling [`subprocess.kill()`](api.md#subprocesskillsignal-error) with no arguments.130- The [`cancelSignal`](#canceling), [`timeout`](#timeout), [`maxBuffer`](output.md#big-output) or [`cleanup`](#current-process-exit) option.131132This does not work when the subprocess is terminated by either:133- Calling [`subprocess.kill()`](../readme.md#subprocesskillsignal-error) with a specific signal.134- Calling [`process.kill(subprocess.pid)`](../readme.md#subprocesspid).133- Calling [`subprocess.kill()`](api.md#subprocesskillsignal-error) with a specific signal.134- Calling [`process.kill(subprocess.pid)`](api.md#subprocesspid).135- Sending a termination signal [from another process](#inter-process-termination).136137Also, this does not work on Windows, because Windows [doesn't support signals](https://nodejs.org/api/process.html#process_signal_events): `SIGKILL` and `SIGTERM` both terminate the subprocess immediately. Other packages (such as [`taskkill`](https://github.com/sindresorhus/taskkill)) can be used to achieve fail-safe termination on Windows.138
4 unmodified lines
143```144145## Inter-process termination146147[`subprocess.kill()`](../readme.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process (for example, a terminal), its [`subprocess.pid`](../readme.md#subprocesspid) can be used instead.147[`subprocess.kill()`](api.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process (for example, a terminal), its [`subprocess.pid`](api.md#subprocesspid) can be used instead.148149```js150const subprocess = execa`npm run build`;151console.log('PID:', subprocess.pid); // PID: 6513
5 unmodified lines
157```158159## Error message and stack trace160161When terminating a subprocess, it is possible to include an error message and stack trace by using [`subprocess.kill(error)`](../readme.md#subprocesskillerror). The `error` argument will be available at [`error.cause`](../readme.md#errorcause).161When terminating a subprocess, it is possible to include an error message and stack trace by using [`subprocess.kill(error)`](api.md#subprocesskillerror). The `error` argument will be available at [`error.cause`](api.md#errorcause).162163```js164try {165 const subprocess = execa`npm run build`;
20 unmodified lines
modified:docs/transform.md+9 added-9 removed
6 unmodified lines
7# 🧙 Transforms89## Summary1011Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) or a [transform options object](../readme.md#transform-options) to the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) or [`stdio`](../readme.md#optionsstdio) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).11Transforms map or filter the input or output of a subprocess. They are defined by passing a [generator function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) or a [transform options object](api.md#transform-options) to the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) or [`stdio`](api.md#optionsstdio) option. It can be [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*).1213```js14import {execa} from 'execa';15
8 unmodified lines
2425## Difference with iteration2627Transforms operate one `line` at a time, just like [`subprocess.iterable()`](lines.md#progressive-splitting). However, unlike iteration, transforms:28- Modify the subprocess' [output](../readme.md#resultstdout) and [streams](../readme.md#subprocessstdout).28- Modify the subprocess' [output](api.md#resultstdout) and [streams](api.md#subprocessstdout).29- Can apply to the subprocess' input.30- Are defined using a [generator function](#summary), [`Duplex`](#duplextransform-streams) stream, Node.js [`Transform`](#duplextransform-streams) stream or web [`TransformStream`](#duplextransform-streams).3132## Filtering
12 unmodified lines
45```4647## Object mode4849By default, [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr)'s transforms must return a string or an `Uint8Array`. However, if the [`objectMode`](../readme.md#transformoptionsobjectmode) transform option is `true`, any type can be returned instead, except `null` or `undefined`. The subprocess' [`result.stdout`](../readme.md#resultstdout)/[`result.stderr`](../readme.md#resultstderr) will be an array of values.49By default, [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr)'s transforms must return a string or an `Uint8Array`. However, if the [`objectMode`](api.md#transformoptionsobjectmode) transform option is `true`, any type can be returned instead, except `null` or `undefined`. The subprocess' [`result.stdout`](api.md#resultstdout)/[`result.stderr`](api.md#resultstderr) will be an array of values.5051```js52const transform = function * (line) {53 yield JSON.parse(line);
4 unmodified lines
58 console.log(stdout); // {...object}59}60```6162[`stdin`](../readme.md#optionsstdin) can also use `objectMode: true`.62[`stdin`](api.md#optionsstdin) can also use `objectMode: true`.6364```js65const transform = function * (line) {66 yield JSON.stringify(line);
4 unmodified lines
71```7273## Sharing state7475State can be shared between calls of the [`transform`](../readme.md#transformoptionstransform) and [`final`](../readme.md#transformoptionsfinal) functions.75State can be shared between calls of the [`transform`](api.md#transformoptionstransform) and [`final`](api.md#transformoptionsfinal) functions.7677```js78let count = 0;79
4 unmodified lines
84```8586## Finalizing8788To create additional lines after the last one, a [`final`](../readme.md#transformoptionsfinal) generator function can be used.88To create additional lines after the last one, a [`final`](api.md#transformoptionsfinal) generator function can be used.8990```js91let count = 0;92
13 unmodified lines
106## Duplex/Transform streams107108A [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) stream, Node.js [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream or web [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) can be used instead of a generator function.109110Like generator functions, web `TransformStream` can be passed either directly or as a [`{transform}` plain object](../readme.md#transform-options). But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.110Like generator functions, web `TransformStream` can be passed either directly or as a [`{transform}` plain object](api.md#transform-options). But `Duplex` and `Transform` must always be passed as a `{transform}` plain object.111112The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](../readme.md#transformoptionsbinary) nor [`preserveNewlines`](../readme.md#transformoptionspreservenewlines) options.112The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](api.md#transformoptionsbinary) nor [`preserveNewlines`](api.md#transformoptionspreservenewlines) options.113114```js115import {createGzip} from 'node:zlib';116import {execa} from 'execa';
14 unmodified lines
131```132133## Combining134135The [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout), [`stderr`](../readme.md#optionsstderr) and [`stdio`](../readme.md#optionsstdio) options can accept [an array of values](output.md#multiple-targets). While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `'inherit'`.135The [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout), [`stderr`](api.md#optionsstderr) and [`stdio`](api.md#optionsstdio) options can accept [an array of values](output.md#multiple-targets). While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `'inherit'`.136137```js138await execa({stdout: [transform, 'inherit']})`npm run build`;139```
18 unmodified lines
modified:docs/windows.md+5 added-5 removed
24 unmodified lines
25Although Windows does not natively support shebangs, Execa adds support for them.2627## Signals2829Only few [signals](termination.md#other-signals) work on Windows with Node.js: [`SIGTERM`](termination.md#sigterm), [`SIGKILL`](termination.md#sigkill) and [`SIGINT`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT). Also, sending signals from other processes is [not supported](termination.md#signal-name-and-description). Finally, the [`forceKillAfterDelay`](../readme.md#optionsforcekillafterdelay) option [is a noop](termination.md#forceful-termination) on Windows.29Only few [signals](termination.md#other-signals) work on Windows with Node.js: [`SIGTERM`](termination.md#sigterm), [`SIGKILL`](termination.md#sigkill) and [`SIGINT`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT). Also, sending signals from other processes is [not supported](termination.md#signal-name-and-description). Finally, the [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option [is a noop](termination.md#forceful-termination) on Windows.3031## Asynchronous I/O3233The default value for the [`stdin`](../readme.md#optionsstdin), [`stdout`](../readme.md#optionsstdout) and [`stderr`](../readme.md#optionsstderr) options is [`'pipe'`](output.md#stdout-and-stderr). This returns the output as [`result.stdout`](../readme.md#resultstdout) and [`result.stderr`](../readme.md#resultstderr) and allows for [manual streaming](streams.md#manual-streaming).33The default value for the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#optionsstdout) and [`stderr`](api.md#optionsstderr) options is [`'pipe'`](output.md#stdout-and-stderr). This returns the output as [`result.stdout`](api.md#resultstdout) and [`result.stderr`](api.md#resultstderr) and allows for [manual streaming](streams.md#manual-streaming).3435Instead of `'pipe'`, `'overlapped'` can be used instead to use [asynchronous I/O](https://learn.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o) under-the-hood on Windows, instead of the default behavior which is synchronous. On other platforms, asynchronous I/O is always used, so `'overlapped'` behaves the same way as `'pipe'`.3637## `cmd.exe` escaping3839If the [`windowsVerbatimArguments`](../readme.md#optionswindowsverbatimarguments) option is `false`, the [command arguments](input.md#command-arguments) are automatically escaped on Windows. When using a [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) [shell](../readme.md#optionsshell), this is `true` by default instead.39If the [`windowsVerbatimArguments`](api.md#optionswindowsverbatimarguments) option is `false`, the [command arguments](input.md#command-arguments) are automatically escaped on Windows. When using a [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) [shell](api.md#optionsshell), this is `true` by default instead.4041This is ignored on other platforms: those are [automatically escaped](escaping.md) by default.4243## Console window4445If the [`windowsHide`](../readme.md#optionswindowshide) option is `false`, the subprocess is run in a new console window. This is necessary to make [`SIGINT` work](https://github.com/nodejs/node/issues/29837) on Windows, and to prevent subprocesses not being cleaned up in [some specific situations](https://github.com/sindresorhus/execa/issues/433).45If the [`windowsHide`](api.md#optionswindowshide) option is `false`, the subprocess is run in a new console window. This is necessary to make [`SIGINT` work](https://github.com/nodejs/node/issues/29837) on Windows, and to prevent subprocesses not being cleaned up in [some specific situations](https://github.com/sindresorhus/execa/issues/433).4647## UID and GID4849By default, subprocesses are run using the current [user](https://en.wikipedia.org/wiki/User_identifier) and [group](https://en.wikipedia.org/wiki/Group_identifier). The [`uid`](../readme.md#optionsuid) and [`gid`](../readme.md#optionsgid) options can be used to set a different user or group.49By default, subprocesses are run using the current [user](https://en.wikipedia.org/wiki/User_identifier) and [group](https://en.wikipedia.org/wiki/Group_identifier). The [`uid`](api.md#optionsuid) and [`gid`](api.md#optionsgid) options can be used to set a different user or group.5051However, since Windows uses a different permission model, those options throw.5253<hr>
4 unmodified lines
modified:readme.md+1 added-1017 removed
93 unmodified lines
94- 📞 [Inter-process communication](docs/ipc.md)95- 🐛 [Debugging](docs/debugging.md)96- 📎 [Windows](docs/windows.md)97- 🔍 [Difference with Bash and zx](docs/bash.md)98- 📔 [API reference](docs/api.md)99100## Usage101102### Promise interface
196 unmodified lines
299 */300}301```302302## API303304### Methods305306#### execa(file, arguments?, options?)307308`file`: `string | URL`\309`arguments`: `string[]`\310`options`: [`Options`](#options)\311_Returns_: [`Subprocess`](#subprocess)312313Executes a command using `file ...arguments`.314315More info on the [syntax](docs/execution.md#array-syntax) and [escaping](docs/escaping.md#array-syntax).316317#### execa\`command\`318#### execa(options)\`command\`319320`command`: `string`\321`options`: [`Options`](#options)\322_Returns_: [`Subprocess`](#subprocess)323324Executes a command. `command` is a [template string](docs/execution.md#template-string-syntax) that includes both the `file` and its `arguments`.325326More info on the [syntax](docs/execution.md#template-string-syntax) and [escaping](docs/escaping.md#template-string-syntax).327328#### execa(options)329330`options`: [`Options`](#options)\331_Returns_: [`execa`](#execafile-arguments-options)332333Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.334335[More info.](docs/execution.md#globalshared-options)336337#### execaSync(file, arguments?, options?)338#### execaSync\`command\`339340Same as [`execa()`](#execafile-arguments-options) but synchronous.341342Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.343344[More info.](docs/execution.md#synchronous-execution)345346#### $(file, arguments?, options?)347348`file`: `string | URL`\349`arguments`: `string[]`\350`options`: [`Options`](#options)\351_Returns_: [`Subprocess`](#subprocess)352353Same as [`execa()`](#execafile-arguments-options) but using [script-friendly default options](docs/scripts.md#script-files).354355Just like `execa()`, this can use the [template string syntax](docs/execution.md#template-string-syntax) or [bind options](docs/execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.356357This is the preferred method when executing multiple commands in a script file.358359[More info.](docs/scripts.md)360361#### execaNode(scriptPath, arguments?, options?)362363`scriptPath`: `string | URL`\364`arguments`: `string[]`\365`options`: [`Options`](#options)\366_Returns_: [`Subprocess`](#subprocess)367368Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#optionsnode) option.369Executes a Node.js file using `node scriptPath ...arguments`.370371Just like `execa()`, this can use the [template string syntax](docs/execution.md#template-string-syntax) or [bind options](docs/execution.md#globalshared-options).372373This is the preferred method when executing Node.js files.374375[More info.](docs/node.md)376377#### execaCommand(command, options?)378379`command`: `string`\380`options`: [`Options`](#options)\381_Returns_: [`Subprocess`](#subprocess)382383Executes a command. `command` is a string that includes both the `file` and its `arguments`.384385This is only intended for very specific cases, such as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). This should be avoided otherwise.386387Just like `execa()`, this can [bind options](docs/execution.md#globalshared-options). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.388389[More info.](docs/escaping.md#user-defined-input)390391### Subprocess392393The return value of all [asynchronous methods](#methods) is both:394- a `Promise` resolving or rejecting with a subprocess [`result`](#result).395- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.396397[More info.](docs/execution.md#subprocess)398399#### subprocess\[Symbol.asyncIterator\]()400401_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)402403Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.404405[More info.](docs/lines.md#progressive-splitting)406407#### subprocess.iterable(readableOptions?)408409`readableOptions`: [`ReadableOptions`](#readableoptions)\410_Returns_: [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)411412Same as [`subprocess[Symbol.asyncIterator]`](#subprocesssymbolasynciterator) except [options](#readableoptions) can be provided.413414[More info.](docs/lines.md#progressive-splitting)415416#### subprocess.pipe(file, arguments?, options?)417418`file`: `string | URL`\419`arguments`: `string[]`\420`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\421_Returns_: [`Promise<Result>`](#result)422423[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.424425This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options) and [pipe-specific options](#pipeoptions) can be specified.426427[More info.](docs/pipe.md#array-syntax)428429#### subprocess.pipe\`command\`430#### subprocess.pipe(options)\`command\`431432`command`: `string`\433`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\434_Returns_: [`Promise<Result>`](#result)435436Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](docs/execution.md#template-string-syntax).437438[More info.](docs/pipe.md#template-string-syntax)439440#### subprocess.pipe(secondSubprocess, pipeOptions?)441442`secondSubprocess`: [`execa()` return value](#subprocess)\443`pipeOptions`: [`PipeOptions`](#pipeoptions)\444_Returns_: [`Promise<Result>`](#result)445446Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using the [return value](#subprocess) of another [`execa()`](#execafile-arguments-options) call instead.447448[More info.](docs/pipe.md#advanced-syntax)449450##### pipeOptions451452Type: `object`453454##### pipeOptions.from455456Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\457Default: `"stdout"`458459Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.460461`"all"` pipes both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.462463[More info.](docs/pipe.md#source-file-descriptor)464465##### pipeOptions.to466467Type: `"stdin" | "fd3" | "fd4" | ...`\468Default: `"stdin"`469470Which [stream](#subprocessstdin) to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.471472[More info.](docs/pipe.md#destination-file-descriptor)473474##### pipeOptions.unpipeSignal475476Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)477478Unpipe the subprocess when the signal aborts.479480[More info.](docs/pipe.md#unpipe)481482#### subprocess.kill(signal, error?)483#### subprocess.kill(error?)484485`signal`: `string | number`\486`error`: `Error`\487_Returns_: `boolean`488489Sends 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](#resultisterminated) the subprocess.490491This returns `false` when the signal could not be sent, for example when the subprocess has already exited.492493When 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).494495[More info.](docs/termination.md)496497#### subprocess.pid498499_Type_: `number | undefined`500501Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).502503This is `undefined` if the subprocess failed to spawn.504505[More info.](docs/termination.md#inter-process-termination)506507#### subprocess.send(message)508509`message`: `unknown`\510_Returns_: `boolean`511512Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.513The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).514515This returns `true` on success.516517This requires the [`ipc`](#optionsipc) option to be `true`.518519[More info.](docs/ipc.md#exchanging-messages)520521#### subprocess.on('message', (message) => void)522523`message`: `unknown`524525Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.526The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).527528This requires the [`ipc`](#optionsipc) option to be `true`.529530[More info.](docs/ipc.md#exchanging-messages)531532#### subprocess.stdin533534Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)535536The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.537538This is `null` if the [`stdin`](#optionsstdin) option is set to [`'inherit'`](docs/input.md#terminal-input), [`'ignore'`](docs/input.md#ignore-input), [`Readable`](docs/streams.md#input) or [`integer`](docs/input.md#terminal-input).539540[More info.](docs/streams.md#manual-streaming)541542#### subprocess.stdout543544Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)545546The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.547548This is `null` if the [`stdout`](#optionsstdout) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.549550[More info.](docs/streams.md#manual-streaming)551552#### subprocess.stderr553554Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)555556The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.557558This is `null` if the [`stderr`](#optionsstdout) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.559560[More info.](docs/streams.md#manual-streaming)561562#### subprocess.all563564Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)565566Stream combining/interleaving [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).567568This requires the [`all`](#optionsall) option to be `true`.569570This is `undefined` if [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.571572More info on [interleaving](docs/output.md#interleaved-output) and [streaming](docs/streams.md#manual-streaming).573574#### subprocess.stdio575576Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)577578The subprocess [`stdin`](#subprocessstdin), [`stdout`](#subprocessstdout), [`stderr`](#subprocessstderr) and [other files descriptors](#optionsstdio) as an array of streams.579580Each array item is `null` if the corresponding [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Stream`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.581582[More info.](docs/streams.md#manual-streaming)583584#### subprocess.readable(readableOptions?)585586`readableOptions`: [`ReadableOptions`](#readableoptions)\587_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream588589Converts the subprocess to a readable stream.590591[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)592593##### readableOptions594595Type: `object`596597##### readableOptions.from598599Type: `"stdout" | "stderr" | "all" | "fd3" | "fd4" | ...`\600Default: `"stdout"`601602Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.603604`"all"` reads both [`stdout`](#subprocessstdout) and [`stderr`](#subprocessstderr). This requires the [`all`](#optionsall) option to be `true`.605606[More info.](docs/streams.md#different-file-descriptor)607608##### readableOptions.binary609610Type: `boolean`\611Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)612613If `false`, iterates over lines. Each line is a string.614615If `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)).616617This is always `true` when the [`encoding`](#optionsencoding) option is binary.618619More info for [iterables](docs/binary.md#iterable) and [streams](docs/binary.md#streams).620621##### readableOptions.preserveNewlines622623Type: `boolean`\624Default: `false` with [`subprocess.iterable()`](#subprocessiterablereadableoptions), `true` with [`subprocess.readable()`](#subprocessreadablereadableoptions)/[`subprocess.duplex()`](#subprocessduplexduplexoptions)625626If both this option and the [`binary`](#readableoptionsbinary) option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.627628[More info.](docs/lines.md#iterable)629630#### subprocess.writable(writableOptions?)631632`writableOptions`: [`WritableOptions`](#writableoptions)\633_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream634635Converts the subprocess to a writable stream.636637[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)638639##### writableOptions640641Type: `object`642643##### writableOptions.to644645Type: `"stdin" | "fd3" | "fd4" | ...`\646Default: `"stdin"`647648Which [stream](#subprocessstdin) to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.649650[More info.](docs/streams.md#different-file-descriptor)651652#### subprocess.duplex(duplexOptions?)653654`duplexOptions`: [`ReadableOptions | WritableOptions`](#readableoptions)\655_Returns_: [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) Node.js stream656657Converts the subprocess to a duplex stream.658659[More info.](docs/streams.md#converting-a-subprocess-to-a-stream)660661### Result662663Type: `object`664665[Result](docs/execution.md#result) of a subprocess execution.666667When the subprocess [fails](docs/errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.668669#### result.stdout670671Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`672673The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).674675This is `undefined` if the [`stdout`](#optionsstdout) option is set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.676677This is an array if the [`lines`](#optionslines) option is `true`, or if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).678679[More info.](docs/output.md#stdout-and-stderr)680681#### result.stderr682683Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`684685The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).686687This is `undefined` if the [`stderr`](#optionsstderr) option is set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.688689This is an array if the [`lines`](#optionslines) option is `true`, or if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).690691[More info.](docs/output.md#stdout-and-stderr)692693#### result.all694695Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`696697The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) interleaved.698699This requires the [`all`](#optionsall) option to be `true`.700701This is `undefined` if both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.702703This is an array if the [`lines`](#optionslines) option is `true`, or if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).704705[More info.](docs/output.md#interleaved-output)706707#### result.stdio708709Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`710711The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).712713Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to [`'inherit'`](docs/output.md#terminal-output), [`'ignore'`](docs/output.md#ignore-output), [`Writable`](docs/streams.md#output) or [`integer`](docs/output.md#terminal-output), or if the [`buffer`](#optionsbuffer) option is `false`.714715Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).716717[More info.](docs/output.md#additional-file-descriptors)718719#### result.pipedFrom720721Type: [`Array<Result | ExecaError>`](#result)722723[Results](#result) of the other subprocesses that were [piped](#pipe-multiple-subprocesses) into this subprocess.724725This array is initially empty and is populated each time the [`subprocess.pipe()`](#subprocesspipefile-arguments-options) method resolves.726727[More info.](docs/pipe.md#errors)728729#### result.command730731Type: `string`732733The file and [arguments](docs/input.md#command-arguments) that were run.734735[More info.](docs/debugging.md#command)736737#### result.escapedCommand738739Type: `string`740741Same as [`command`](#resultcommand) but escaped.742743[More info.](docs/debugging.md#command)744745#### result.cwd746747Type: `string`748749The [current directory](#optionscwd) in which the command was run.750751[More info.](docs/environment.md#current-directory)752753#### result.durationMs754755Type: `number`756757Duration of the subprocess, in milliseconds.758759[More info.](docs/debugging.md#duration)760761#### result.failed762763Type: `boolean`764765Whether the subprocess failed to run.766767[More info.](docs/errors.md#subprocess-failure)768769#### result.timedOut770771Type: `boolean`772773Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.774775[More info.](docs/termination.md#timeout)776777#### result.isCanceled778779Type: `boolean`780781Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.782783[More info.](docs/termination.md#canceling)784785#### result.isMaxBuffer786787Type: `boolean`788789Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.790791[More info.](docs/output.md#big-output)792793#### result.isTerminated794795Type: `boolean`796797Whether the subprocess was terminated by a [signal](docs/termination.md#signal-termination) (like [`SIGTERM`](docs/termination.md#sigterm)) sent by either:798- The current process.799- [Another process](docs/termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).800801[More info.](docs/termination.md#signal-name-and-description)802803#### result.exitCode804805Type: `number | undefined`806807The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.808809This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).810811[More info.](docs/errors.md#exit-code)812813#### result.signal814815Type: `string | undefined`816817The name of the [signal](docs/termination.md#signal-termination) (like [`SIGTERM`](docs/termination.md#sigterm)) that terminated the subprocess, sent by either:818- The current process.819- [Another process](docs/termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).820821If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.822823[More info.](docs/termination.md#signal-name-and-description)824825#### result.signalDescription826827Type: `string | undefined`828829A human-friendly description of the [signal](docs/termination.md#signal-termination) that was used to terminate the subprocess.830831If 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.832833[More info.](docs/termination.md#signal-name-and-description)834835### ExecaError836### ExecaSyncError837838Type: `Error`839840Exception thrown when the subprocess [fails](docs/errors.md#subprocess-failure).841842This has the same shape as [successful results](#result), with the following additional properties.843844[More info.](docs/errors.md)845846#### error.message847848Type: `string`849850Error message when the subprocess [failed](docs/errors.md#subprocess-failure) to run.851852[More info.](docs/errors.md#error-message)853854#### error.shortMessage855856Type: `string`857858This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](docs/output.md).859860[More info.](docs/errors.md#error-message)861862#### error.originalMessage863864Type: `string | undefined`865866Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](docs/output.md) and some additional information added by Execa.867868[More info.](docs/errors.md#error-message)869870#### error.cause871872Type: `unknown | undefined`873874Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).875876This is usually an `Error` instance.877878[More info.](docs/termination.md#error-message-and-stack-trace)879880#### error.code881882Type: `string | undefined`883884Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.885886### Options887888Type: `object`889890This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).891892The following options [can specify different values](docs/output.md#stdoutstderr-specific-options) for [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr): [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`buffer`](#optionsbuffer), [`maxBuffer`](#optionsmaxbuffer).893894#### options.preferLocal895896Type: `boolean`\897Default: `true` with [`$`](#file-arguments-options), `false` otherwise898899Prefer locally installed binaries when looking for a binary to execute.900901[More info.](docs/environment.md#local-binaries)902903#### options.localDir904905Type: `string | URL`\906Default: [`cwd`](#optionscwd) option907908Preferred path to find locally installed binaries, when using the [`preferLocal`](#optionspreferlocal) option.909910[More info.](docs/environment.md#local-binaries)911912#### options.node913914Type: `boolean`\915Default: `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise916917If `true`, runs with Node.js. The first argument must be a Node.js file.918919[More info.](docs/node.md)920921#### options.nodeOptions922923Type: `string[]`\924Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)925926List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).927928Requires the [`node`](#optionsnode) option to be `true`.929930[More info.](docs/node.md#nodejs-cli-flags)931932#### options.nodePath933934Type: `string | URL`\935Default: [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)936937Path to the Node.js executable.938939Requires the [`node`](#optionsnode) option to be `true`.940941[More info.](docs/node.md#nodejs-version)942943#### options.shell944945Type: `boolean | string | URL`\946Default: `false`947948If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).949950Uses [`/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.951952We [recommend against](docs/shell.md#avoiding-shells) using this option.953954[More info.](docs/shell.md)955956#### options.cwd957958Type: `string | URL`\959Default: `process.cwd()`960961Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.962963This is also used to resolve the [`nodePath`](#optionsnodepath) option when it is a relative path.964965[More info.](docs/environment.md#current-directory)966967#### options.env968969Type: `object`\970Default: [`process.env`](https://nodejs.org/api/process.html#processenv)971972[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).973974Unless the [`extendEnv`](#optionsextendenv) option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).975976[More info.](docs/input.md#environment-variables)977978#### options.extendEnv979980Type: `boolean`\981Default: `true`982983If `true`, the subprocess uses both the [`env`](#optionsenv) option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).984If `false`, only the `env` option is used, not `process.env`.985986[More info.](docs/input.md#environment-variables)987988#### options.input989990Type: `string | Uint8Array | stream.Readable`991992Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).993994See also the [`inputFile`](#optionsinputfile) and [`stdin`](#optionsstdin) options.995996[More info.](docs/input.md#string-input)997998#### options.inputFile9991000Type: `string | URL`10011002Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).10031004See also the [`input`](#optionsinput) and [`stdin`](#optionsstdin) options.10051006[More info.](docs/input.md#file-input)10071008#### options.stdin10091010Type: `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)\1011Default: `'inherit'` with [`$`](#file-arguments-options), `'pipe'` otherwise10121013How to setup the subprocess' [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/streams.md#manual-streaming), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/input.md#ignore-input), [`'inherit'`](docs/input.md#terminal-input), a [file descriptor integer](docs/input.md#terminal-input), a [Node.js `Readable` stream](docs/streams.md#input), a web [`ReadableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/input.md#file-input), a [file URL](docs/input.md#file-input), an [`Iterable`](docs/streams.md#iterables-as-input) (including an [array of strings](docs/input.md#string-input)), an [`AsyncIterable`](docs/streams.md#iterables-as-input), an [`Uint8Array`](docs/binary.md#binary-input), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).10141015This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.10161017More info on [available values](docs/input.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).10181019#### options.stdout10201021Type: `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)\1022Default: `pipe`10231024How to setup the subprocess' [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/output.md#stdout-and-stderr), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/output.md#ignore-output), [`'inherit'`](docs/output.md#terminal-output), a [file descriptor integer](docs/output.md#terminal-output), a [Node.js `Writable` stream](docs/streams.md#output), a web [`WritableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/output.md#file-output), a [file URL](docs/output.md#file-output), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).10251026This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.10271028More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).10291030#### options.stderr10311032Type: `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)\1033Default: `pipe`10341035How to setup the subprocess' [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be [`'pipe'`](docs/output.md#stdout-and-stderr), [`'overlapped'`](docs/windows.md#asynchronous-io), [`'ignore`](docs/output.md#ignore-output), [`'inherit'`](docs/output.md#terminal-output), a [file descriptor integer](docs/output.md#terminal-output), a [Node.js `Writable` stream](docs/streams.md#output), a web [`WritableStream`](docs/streams.md#web-streams), a [`{ file: 'path' }` object](docs/output.md#file-output), a [file URL](docs/output.md#file-output), a [generator function](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams).10361037This can be an [array of values](docs/output.md#multiple-targets) such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.10381039More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).10401041#### options.stdio10421043Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | TransformStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex | TransformStream}>` (or a tuple of those types)\1044Default: `pipe`10451046Like 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'}`.10471048A single string can be used [as a shortcut](docs/output.md#shortcut).10491050The array can have more than 3 items, to create [additional file descriptors](docs/output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).10511052More info on [available values](docs/output.md), [streaming](docs/streams.md) and [transforms](docs/transform.md).10531054#### options.all10551056Type: `boolean`\1057Default: `false`10581059Add a [`subprocess.all`](#subprocessall) stream and a [`result.all`](#resultall) property.10601061[More info.](docs/output.md#interleaved-output)10621063#### options.encoding10641065Type: `'utf8' | 'utf16le' | 'buffer' | 'hex' | 'base64' | 'base64url' | 'latin1' | 'ascii'`\1066Default: `'utf8'`10671068If 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).10691070If it outputs binary data instead, this should be either:1071- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).1072- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.10731074The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).10751076[More info.](docs/binary.md)10771078#### options.lines10791080Type: `boolean`\1081Default: `false`10821083Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.10841085This cannot be used if the [`encoding`](#optionsencoding) option is [binary](docs/binary.md#binary-output).10861087By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).10881089[More info.](docs/lines.md#simple-splitting)10901091#### options.stripFinalNewline10921093Type: `boolean`\1094Default: `true`10951096Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10971098If the [`lines`](#optionslines) option is true, this applies to each output line instead.10991100By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).11011102[More info.](docs/lines.md#newlines)11031104#### options.maxBuffer11051106Type: `number`\1107Default: `100_000_000`11081109Largest amount of data allowed on [`stdout`](#resultstdout), [`stderr`](#resultstderr) and [`stdio`](#resultstdio).11101111By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).11121113[More info.](docs/output.md#big-output)11141115#### options.buffer11161117Type: `boolean`\1118Default: `true`11191120When `buffer` is `false`, the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties are not set.11211122By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).11231124[More info.](docs/output.md#low-memory)11251126#### options.ipc11271128Type: `boolean`\1129Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise11301131Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).11321133[More info.](docs/ipc.md)11341135#### options.serialization11361137Type: `'json' | 'advanced'`\1138Default: `'advanced'`11391140Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option.11411142[More info.](docs/ipc.md#message-type)11431144#### options.verbose11451146Type: `'none' | 'short' | 'full'`\1147Default: `'none'`11481149If `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.11501151If `verbose` is `'full'`, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and `stderr` are also printed.11521153By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](docs/output.md#stdoutstderr-specific-options).11541155[More info.](docs/debugging.md#verbose-mode)11561157#### options.reject11581159Type: `boolean`\1160Default: `true`11611162Setting this to `false` resolves the [result's promise](#subprocess) with the [error](#execaerror) instead of rejecting it.11631164[More info.](docs/errors.md#preventing-exceptions)11651166#### options.timeout11671168Type: `number`\1169Default: `0`11701171If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.11721173On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.11741175[More info.](docs/termination.md#timeout)11761177#### options.cancelSignal11781179Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)11801181You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).11821183When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.11841185[More info.](docs/termination.md#canceling)11861187#### options.forceKillAfterDelay11881189Type: `number | false`\1190Default: `5000`11911192If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).11931194[More info.](docs/termination.md#forceful-termination)11951196#### options.killSignal11971198Type: `string | number`\1199Default: `'SIGTERM'`12001201Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.12021203This can be either a name (like [`'SIGTERM'`](docs/termination.md#sigterm)) or a number (like `9`).12041205[More info.](docs/termination.md#default-signal)12061207#### options.detached12081209Type: `boolean`\1210Default: `false`12111212Run the subprocess independently from the current process.12131214[More info.](docs/environment.md#background-subprocess)12151216#### options.cleanup12171218Type: `boolean`\1219Default: `true`12201221Kill the subprocess when the current process exits.12221223[More info.](docs/termination.md#current-process-exit)12241225#### options.uid12261227Type: `number`\1228Default: current user identifier12291230Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.12311232[More info.](docs/windows.md#uid-and-gid)12331234#### options.gid12351236Type: `number`\1237Default: current group identifier12381239Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.12401241[More info.](docs/windows.md#uid-and-gid)12421243#### options.argv012441245Type: `string`\1246Default: file being executed12471248Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.12491250#### options.windowsHide12511252Type: `boolean`\1253Default: `true`12541255On Windows, do not create a new console window.12561257[More info.](docs/windows.md#console-window)12581259#### options.windowsVerbatimArguments12601261Type: `boolean`\1262Default: `true` if the [`shell`](#optionsshell) option is `true`, `false` otherwise12631264If `false`, escapes the command arguments on Windows.12651266[More info.](docs/windows.md#cmdexe-escaping)12671268### Transform options12691270A transform or an [array of transforms](docs/transform.md#combining) can be passed to the [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option.12711272A transform is either a [generator function](#transformoptionstransform) or a plain object with the following members.12731274[More info.](docs/transform.md)12751276#### transformOptions.transform12771278Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`12791280Map or [filter](docs/transform.md#filtering) the [input](docs/input.md) or [output](docs/output.md) of the subprocess.12811282More info [here](docs/transform.md#summary) and [there](docs/transform.md#sharing-state).12831284#### transformOptions.final12851286Type: `GeneratorFunction<string | Uint8Array | unknown>` | `AsyncGeneratorFunction<string | Uint8Array | unknown>`12871288Create additional lines after the last one.12891290[More info.](docs/transform.md#finalizing)12911292#### transformOptions.binary12931294Type: `boolean`\1295Default: `false`12961297If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.12981299[More info.](docs/binary.md#transforms)13001301#### transformOptions.preserveNewlines13021303Type: `boolean`\1304Default: `false`13051306If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.13071308[More info.](docs/lines.md#transforms)13091310#### transformOptions.objectMode13111312Type: `boolean`\1313Default: `false`13141315If `true`, allow [`transformOptions.transform`](#transformoptionstransform) and [`transformOptions.final`](#transformoptionsfinal) to return any type, not just `string` or `Uint8Array`.13161317[More info.](docs/transform.md#object-mode)1318303## Related304305- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa306- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version
5 unmodified lines