api.md
This file
Path
docs/api.md
1,029 lines · 40.4 KiB · Markdown
Last changed by
Move API reference to its own page (#996)ehmickybefore adoption7cde496
History of this fileTake it
Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 1–1029why, one step back1<picture>2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 📔 API reference89This lists all available [methods](#methods) and their [options](#options). This also describes the properties of the [subprocess](#subprocess), [result](#result) and [error](#execaerror) they return.1011## Methods1213### execa(file, arguments?, options?)1415`file`: `string | URL`\16`arguments`: `string[]`\17`options`: [`Options`](#options)\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)