Skip to content
Myr

Document and type more `subprocess.*` properties/methods (#968)

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

authored by ehmicky · committed by GitHub · parent 1e9e47e · Browse files · 4 files+296 added−74 removed
This commit

State

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

Diff stats

4 files+296 added−74 removed

  • other:+296 added−74 removed

4 files+296 added−74 removed

modified:docs/scripts.md+1 added-1 removed
823 unmodified lines
824Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#file-arguments-options) and [`$(options)`](../readme.md#execaoptions).825826[No special binary](#main-binary) is recommended, no [global variable](#global-variables) is injected: scripts are regular Node.js files.827828Execa is a thin wrapper around the core Node.js [`child_process` module](https://nodejs.org/api/child_process.html). Unlike zx, it lets you use [any of its native features](#background-subprocesses): [`pid`](#pid), [IPC](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback), [`unref()`](https://nodejs.org/api/child_process.html#subprocessunref), [`detached`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`uid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`gid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`cancelSignal`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), etc.828Execa is a thin wrapper around the core Node.js [`child_process` module](https://nodejs.org/api/child_process.html). Unlike zx, it lets you use [any of its native features](#background-subprocesses): [`pid`](#pid), [IPC](../readme.md#optionsipc), [`unref()`](https://nodejs.org/api/child_process.html#subprocessunref), [`detached`](../readme.md#optionsdetached), [`uid`](../readme.md#optionsuid), [`gid`](../readme.md#optionsgid), [`cancelSignal`](../readme.md#optionscancelsignal), etc.829830### Modularity831832zx includes many builtin utilities: `fetch()`, `question()`, `sleep()`, `stdin()`, `retry()`, `spinner()`, `chalk`, `fs-extra`, `os`, `path`, `globby`, `yaml`, `minimist`, `which`, Markdown scripts, remote scripts.
16 unmodified lines
modified:index.d.ts+103 added-31 removed
441 unmodified lines
442 */443 readonly inputFile?: string | URL;444445 /**446 [How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:447 - `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.446 How to setup the subprocess' standard input. This can be:447 - `'pipe'`: Sets `subprocess.stdin` stream.448 - `'overlapped'`: Like `'pipe'` but asynchronous on Windows.449 - `'ignore'`: Do not use `stdin`.450 - `'inherit'`: Re-use the current process' `stdin`.451 - an integer: Re-use a specific file descriptor from the current process.
12 unmodified lines
464 */465 readonly stdin?: StdinOptionCommon<IsSync>;466467 /**468 [How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:469 - `'pipe'`: Sets `result.stdout` (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).468 How to setup the subprocess' standard output. This can be:469 - `'pipe'`: Sets `result.stdout` (as a string or `Uint8Array`) and `subprocess.stdout` (as a stream).470 - `'overlapped'`: Like `'pipe'` but asynchronous on Windows.471 - `'ignore'`: Do not use `stdout`.472 - `'inherit'`: Re-use the current process' `stdout`.473 - an integer: Re-use a specific file descriptor from the current process.
10 unmodified lines
484 */485 readonly stdout?: StdoutStderrOptionCommon<IsSync>;486487 /**488 [How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:489 - `'pipe'`: Sets `result.stderr` (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).488 How to setup the subprocess' standard error. This can be:489 - `'pipe'`: Sets `result.stderr` (as a string or `Uint8Array`) and `subprocess.stderr` (as a stream).490 - `'overlapped'`: Like `'pipe'` but asynchronous on Windows.491 - `'ignore'`: Do not use `stderr`.492 - `'inherit'`: Re-use the current process' `stderr`.493 - an integer: Re-use a specific file descriptor from the current process.
138 unmodified lines
632633 /**634 Signal used to terminate the subprocess when:635 - using the `cancelSignal`, `timeout`, `maxBuffer` or `cleanup` option636 - calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments636 - calling `subprocess.kill()` with no arguments637638 This can be either a name (like `"SIGTERM"`) or a number (like `9`).639640 @default 'SIGTERM'
6 unmodified lines
647 The grace period is 5 seconds by default. This feature can be disabled with `false`.648649 This works when the subprocess is terminated by either:650 - the `cancelSignal`, `timeout`, `maxBuffer` or `cleanup` option651 - calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments651 - calling `subprocess.kill()` with no arguments652653 This does not work when the subprocess is terminated by either:654 - calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with an argument654 - calling `subprocess.kill()` with an argument655 - calling [`process.kill(subprocess.pid)`](https://nodejs.org/api/process.html#processkillpid-signal)656 - sending a termination signal from another process657658 Also, 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.
31 unmodified lines
690 readonly verbose?: 'none' | 'short' | 'full';691692 /**693 Kill the subprocess when the current process exits unless either:694 - the subprocess is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)695 - the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit694 - the subprocess is `detached`.695 - the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit.696697 @default true698 */699 readonly cleanup?: Unless<IsSync, boolean>;
16 unmodified lines
716 */717 readonly all?: boolean;718719 /**720 Enables exchanging messages with the subprocess using [`subprocess.send(value)`](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [`subprocess.on('message', (value) => {})`](https://nodejs.org/api/child_process.html#event-message).720 Enables exchanging messages with the subprocess using `subprocess.send(message)` and `subprocess.on('message', (message) => {})`.721722 @default `true` if the `node` option is enabled, `false` otherwise723 */724 readonly ipc?: Unless<IsSync, boolean>;
9 unmodified lines
734 */735 readonly serialization?: Unless<IsSync, 'json' | 'advanced'>;736737 /**738 Prepare subprocess to run independently of the current process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).738 Prepare subprocess to run independently of the current process. Specific behavior depends on the platform.739740 @default false741 */742 readonly detached?: Unless<IsSync, boolean>;
83 unmodified lines
826827 /**828 The output of the subprocess on `stdout`.829830 This is `undefined` if the `stdout` option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `lines` option is `true`, or if the `stdout` option is a transform in object mode.830 This is `undefined` if the `stdout` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This is an array if the `lines` option is `true`, or if the `stdout` option is a transform in object mode.831 */832 stdout: StdioOutput<'1', OptionsType>;833834 /**835 The output of the subprocess on `stderr`.836837 This is `undefined` if the `stderr` option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.837 This is `undefined` if the `stderr` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.838 */839 stderr: StdioOutput<'2', OptionsType>;840841 /**842 The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.843844 Items are `undefined` when their corresponding `stdio` option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a transform in object mode.844 Items are `undefined` when their corresponding `stdio` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. Items are arrays when their corresponding `stdio` option is a transform in object mode.845 */846 stdio: StdioArrayOutput<OptionsType>;847848 /**
49 unmodified lines
898 */899 isMaxBuffer: boolean;900901 /**902 The output of the subprocess with `stdout` and `stderr` interleaved.902 The output of the subprocess with `result.stdout` and `result.stderr` interleaved.903904 This is `undefined` if either:905 - the `all` option is `false` (default value)906 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)905 - the `all` option is `false` (default value).906 - both `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`.907908 This is an array if the `lines` option is `true`, or if either the `stdout` or `stderr` option is a transform in object mode.909 */910 all: AllOutput<OptionsType>;
129 unmodified lines
1040> = StreamResultIgnored extends true1041 ? null1042 : InputOutputStream<IsInputStdioDescriptor<FdNumber, OptionsType>>;10431044// Type of `subprocess.stdio`1045type StdioArrayStreams<OptionsType extends Options = Options> = MapStdioStreams<StdioArrayOption<OptionsType>, OptionsType>;10461047// We cannot use mapped types because it must be compatible with Node.js `ChildProcess["stdio"]` which uses a tuple with exactly 5 items1048type MapStdioStreams<1049 StdioOptionsArrayType extends StdioOptionsArray,1050 OptionsType extends Options = Options,1051> = [1052 StreamUnlessIgnored<'0', OptionsType>,1053 StreamUnlessIgnored<'1', OptionsType>,1054 StreamUnlessIgnored<'2', OptionsType>,1055 '3' extends keyof StdioOptionsArrayType ? StreamUnlessIgnored<'3', OptionsType> : never,1056 '4' extends keyof StdioOptionsArrayType ? StreamUnlessIgnored<'4', OptionsType> : never,1057];10581059type InputOutputStream<IsInput extends boolean> = IsInput extends true1060 ? Writable1061 : Readable;1062
130 unmodified lines
1193 ? Uint8Array1194 : string1195>;11961197type HasIpc<OptionsType extends Options> = OptionsType['ipc'] extends true1198 ? true1199 : OptionsType['stdio'] extends StdioOptionsArray1200 ? 'ipc' extends OptionsType['stdio'][number] ? true : false1201 : false;12021203export type ExecaResultPromise<OptionsType extends Options = Options> = {1204 /**1205 Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).12061207 This is `undefined` if the subprocess failed to spawn.1208 */1209 pid?: number;12101211 /**1212 Send a `message` to the subprocess. The type of `message` depends on the `serialization` option.1213 The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).12141215 This returns `true` on success.12161217 This requires the `ipc` option to be `true`.12181219 [More info.](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback)1220 */1221 send: HasIpc<OptionsType> extends true ? ChildProcess['send'] : undefined;12221223 /**1224 The subprocess `stdin` as a stream.12251226 This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.12271228 This is intended for advanced cases. Please consider using the `stdin` option, `input` option, `inputFile` option, or `subprocess.pipe()` instead.1229 */1230 stdin: StreamUnlessIgnored<'0', OptionsType>;12311232 /**1233 The subprocess `stdout` as a stream.12341235 This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`.12361237 This is intended for advanced cases. Please consider using `result.stdout`, the `stdout` option, `subprocess.iterable()`, or `subprocess.pipe()` instead.1238 */1239 stdout: StreamUnlessIgnored<'1', OptionsType>;12401241 /**1242 The subprocess `stderr` as a stream.12431244 This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`.12451246 This is intended for advanced cases. Please consider using `result.stderr`, the `stderr` option, `subprocess.iterable()`, or `subprocess.pipe()` instead.1247 */1248 stderr: StreamUnlessIgnored<'2', OptionsType>;12491250 /**1190 Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).1251 Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.12521253 This is `undefined` if either:1193 - the `all` option is `false` (the default value)1194 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)1254 - the `all` option is `false` (the default value).1255 - both `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`.12561257 This is intended for advanced cases. Please consider using `result.all`, the `stdout`/`stderr` option, `subprocess.iterable()`, or `subprocess.pipe()` instead.1258 */1259 all: AllStream<OptionsType>;12601261 /**1262 The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.12631264 Each array item is `null` if the corresponding `stdin`, `stdout`, `stderr` or `stdio` option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`.12651266 This is intended for advanced cases. Please consider using `result.stdio`, the `stdio` option, `subprocess.iterable()` or `subprocess.pipe()` instead.1267 */1268 stdio: StdioArrayStreams<OptionsType>;12691270 catch<ResultType = never>(1271 onRejected?: (reason: ExecaError<OptionsType>) => ResultType | PromiseLike<ResultType>1272 ): Promise<ExecaResult<OptionsType> | ResultType>;1273
23 unmodified lines
12971298 /**1299 Converts the subprocess to a readable stream.13001229 Unlike [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), 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. This means you do not need to `await` the subprocess' promise. On the other hand, you do need to handle to the stream `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.1301 Unlike `subprocess.stdout`, 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. This means you do not need to `await` the subprocess' promise. On the other hand, you do need to handle to the stream `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.13021303 Before using this method, please first consider the `stdin`/`stdout`/`stderr`/`stdio` options, `subprocess.pipe()` or `subprocess.iterable()`.1304 */1305 readable(readableOptions?: ReadableOptions): Readable;13061307 /**1308 Converts the subprocess to a writable stream.13091238 Unlike [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), 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. This means you do not need to `await` the subprocess' promise. On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.1310 Unlike `subprocess.stdin`, 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. This means you do not need to `await` the subprocess' promise. On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.13111312 Before using this method, please first consider the `stdin`/`stdout`/`stderr`/`stdio` options or `subprocess.pipe()`.1313 */1314 writable(writableOptions?: WritableOptions): Writable;
7 unmodified lines
1322 */1323 duplex(duplexOptions?: DuplexOptions): Duplex;1324} & PipableSubprocess;13251254export type ExecaSubprocess<OptionsType extends Options = Options> = ChildProcess &1326export type ExecaSubprocess<OptionsType extends Options = Options> = Omit<ChildProcess, keyof ExecaResultPromise<OptionsType>> &1327ExecaResultPromise<OptionsType> &1328Promise<ExecaResult<OptionsType>>;13291330type TemplateExpression = string | number | CommonResultInstance
223 unmodified lines
15541555Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.15561557The following features cannot be used:1486- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1487- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.1488- Signal termination: [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`subprocess.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `cleanup` option, `cancelSignal` option, `forceKillAfterDelay` option.1558- Streams: `subprocess.stdin`, `subprocess.stdout`, `subprocess.stderr`, `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1559- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be `'overlapped'`, an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.1560- Signal termination: `subprocess.kill()`, `subprocess.pid`, `cleanup` option, `cancelSignal` option, `forceKillAfterDelay` option.1561- Piping multiple processes: `subprocess.pipe()`.1562- `subprocess.iterable()`.1563- `ipc` and `serialization` options.1564- `result.all` is not interleaved.
113 unmodified lines
16781679Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.16801681The following features cannot be used:1610- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1611- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.1612- Signal termination: [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`subprocess.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `cleanup` option, `cancelSignal` option, `forceKillAfterDelay` option.1682- Streams: `subprocess.stdin`, `subprocess.stdout`, `subprocess.stderr`, `subprocess.readable()`, `subprocess.writable()`, `subprocess.duplex()`.1683- The `stdin`, `stdout`, `stderr` and `stdio` options cannot be `'overlapped'`, an async iterable, an async transform, a `Duplex`, nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.1684- Signal termination: `subprocess.kill()`, `subprocess.pid`, `cleanup` option, `cancelSignal` option, `forceKillAfterDelay` option.1685- Piping multiple processes: `subprocess.pipe()`.1686- `subprocess.iterable()`.1687- `ipc` and `serialization` options.1688- `result.all` is not interleaved.
134 unmodified lines
modified:index.test-d.ts+66 added-1 removed
515 unmodified lines
516 expectType<string>(unicornsResult.stdio[2]);517 expectType<string>(unicornsResult.all);518 expectType<string | undefined>(unicornsResult.stdio[3 as number]);519520 expectType<number | undefined>(execaBufferPromise.pid);521522 expectType<boolean>(execa('unicorns', {ipc: true}).send({}));523 execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ipc']}).send({});524 execa('unicorns', {stdio: ['pipe', 'pipe', 'ipc', 'pipe']}).send({});525 execa('unicorns', {ipc: true}).send('message');526 execa('unicorns', {ipc: true}).send({}, undefined, {keepOpen: true});527 expectError(execa('unicorns', {ipc: true}).send({}, true));528 expectType<undefined>(execa('unicorns', {}).send);529 expectType<undefined>(execa('unicorns', {ipc: false}).send);530 expectType<undefined>(execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe']}).send);531532 expectType<Writable>(execaBufferPromise.stdin);533 expectType<Writable>(execaBufferPromise.stdio[0]);534 expectType<Readable>(execaBufferPromise.stdout);535 expectType<Readable>(execaBufferPromise.stdio[1]);536 expectType<Readable>(execaBufferPromise.stderr);537 expectType<Readable>(execaBufferPromise.stdio[2]);538 expectType<Readable>(execaBufferPromise.all);539 expectError(execaBufferPromise.stdio[3].destroy());540 expectType<Uint8Array>(bufferResult.stdout);541 expectType<Uint8Array>(bufferResult.stdio[1]);542 expectType<Uint8Array>(bufferResult.stderr);543 expectType<Uint8Array>(bufferResult.stdio[2]);544 expectType<Uint8Array>(bufferResult.all);545546 expectType<Writable>(execaHexPromise.stdin);547 expectType<Writable>(execaHexPromise.stdio[0]);548 expectType<Readable>(execaHexPromise.stdout);549 expectType<Readable>(execaHexPromise.stdio[1]);550 expectType<Readable>(execaHexPromise.stderr);551 expectType<Readable>(execaHexPromise.stdio[2]);552 expectType<Readable>(execaHexPromise.all);553 expectError(execaHexPromise.stdio[3].destroy());554 expectType<string>(hexResult.stdout);555 expectType<string>(hexResult.stdio[1]);556 expectType<string>(hexResult.stderr);557 expectType<string>(hexResult.stdio[2]);
21 unmodified lines
579 expectType<string>(linesHexResult.all);580581 const noBufferPromise = execa('unicorns', {buffer: false, all: true});582 expectType<Writable>(noBufferPromise.stdin);583 expectType<Writable>(noBufferPromise.stdio[0]);584 expectType<Readable>(noBufferPromise.stdout);585 expectType<Readable>(noBufferPromise.stdio[1]);586 expectType<Readable>(noBufferPromise.stderr);587 expectType<Readable>(noBufferPromise.stdio[2]);588 expectType<Readable>(noBufferPromise.all);589 expectError(noBufferPromise.stdio[3].destroy());590 const noBufferResult = await noBufferPromise;591 expectType<undefined>(noBufferResult.stdout);592 expectType<undefined>(noBufferResult.stdio[1]);593 expectType<undefined>(noBufferResult.stderr);
4 unmodified lines
598 expectType<Writable>(multipleStdinPromise.stdin);599600 const multipleStdoutPromise = execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe'], all: true});601 expectType<Writable>(multipleStdoutPromise.stdin);602 expectType<Writable>(multipleStdoutPromise.stdio[0]);603 expectType<Readable>(multipleStdoutPromise.stdout);604 expectType<Readable>(multipleStdoutPromise.stdio[1]);605 expectType<Readable>(multipleStdoutPromise.stderr);606 expectType<Readable>(multipleStdoutPromise.stdio[2]);607 expectType<Readable>(multipleStdoutPromise.all);608 expectError(multipleStdoutPromise.stdio[3].destroy());609 const multipleStdoutResult = await multipleStdoutPromise;610 expectType<string>(multipleStdoutResult.stdout);611 expectType<string>(multipleStdoutResult.stdio[1]);612 expectType<string>(multipleStdoutResult.stderr);
1 unmodified line
614 expectType<string>(multipleStdoutResult.all);615616 const ignoreAnyPromise = execa('unicorns', {stdin: 'ignore', stdout: 'ignore', stderr: 'ignore', all: true});617 expectType<null>(ignoreAnyPromise.stdin);618 expectType<null>(ignoreAnyPromise.stdio[0]);619 expectType<null>(ignoreAnyPromise.stdout);620 expectType<null>(ignoreAnyPromise.stdio[1]);621 expectType<null>(ignoreAnyPromise.stderr);622 expectType<null>(ignoreAnyPromise.stdio[2]);623 expectType<undefined>(ignoreAnyPromise.all);624 expectError(ignoreAnyPromise.stdio[3].destroy());625 const ignoreAnyResult = await ignoreAnyPromise;626 expectType<undefined>(ignoreAnyResult.stdout);627 expectType<undefined>(ignoreAnyResult.stdio[1]);628 expectType<undefined>(ignoreAnyResult.stderr);
1 unmodified line
630 expectType<undefined>(ignoreAnyResult.all);631632 const ignoreAllPromise = execa('unicorns', {stdio: 'ignore', all: true});633 expectType<null>(ignoreAllPromise.stdin);634 expectType<null>(ignoreAllPromise.stdio[0]);635 expectType<null>(ignoreAllPromise.stdout);636 expectType<null>(ignoreAllPromise.stdio[1]);637 expectType<null>(ignoreAllPromise.stderr);638 expectType<null>(ignoreAllPromise.stdio[2]);639 expectType<undefined>(ignoreAllPromise.all);640 expectError(ignoreAllPromise.stdio[3].destroy());641 const ignoreAllResult = await ignoreAllPromise;642 expectType<undefined>(ignoreAllResult.stdout);643 expectType<undefined>(ignoreAllResult.stdio[1]);644 expectType<undefined>(ignoreAllResult.stderr);645 expectType<undefined>(ignoreAllResult.stdio[2]);646 expectType<undefined>(ignoreAllResult.all);647612 const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['ignore', 'ignore', 'pipe'], all: true});648 const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['ignore', 'ignore', 'pipe', 'pipe'], all: true});649 expectType<null>(ignoreStdioArrayPromise.stdin);650 expectType<null>(ignoreStdioArrayPromise.stdio[0]);651 expectType<null>(ignoreStdioArrayPromise.stdout);652 expectType<null>(ignoreStdioArrayPromise.stdio[1]);653 expectType<Readable>(ignoreStdioArrayPromise.stderr);654 expectType<Readable>(ignoreStdioArrayPromise.stdio[2]);655 expectType<Readable>(ignoreStdioArrayPromise.all);656 expectType<Readable>(ignoreStdioArrayPromise.stdio[3]);657 const ignoreStdioArrayResult = await ignoreStdioArrayPromise;658 expectType<undefined>(ignoreStdioArrayResult.stdout);659 expectType<undefined>(ignoreStdioArrayResult.stdio[1]);660 expectType<string>(ignoreStdioArrayResult.stderr);661 expectType<string>(ignoreStdioArrayResult.stdio[2]);662 expectType<string>(ignoreStdioArrayResult.all);663664 const ignoreStdioArrayReadPromise = execa('unicorns', {stdio: ['ignore', 'ignore', 'pipe', new Uint8Array()], all: true});665 expectType<Writable>(ignoreStdioArrayReadPromise.stdio[3]);666667 const ignoreStdinPromise = execa('unicorns', {stdin: 'ignore'});668 expectType<null>(ignoreStdinPromise.stdin);669670 const ignoreStdoutPromise = execa('unicorns', {stdout: 'ignore', all: true});671 expectType<Writable>(ignoreStdoutPromise.stdin);672 expectType<Writable>(ignoreStdoutPromise.stdio[0]);673 expectType<null>(ignoreStdoutPromise.stdout);674 expectType<null>(ignoreStdoutPromise.stdio[1]);675 expectType<Readable>(ignoreStdoutPromise.stderr);676 expectType<Readable>(ignoreStdoutPromise.stdio[2]);677 expectType<Readable>(ignoreStdoutPromise.all);678 expectError(ignoreStdoutPromise.stdio[3].destroy());679 const ignoreStdoutResult = await ignoreStdoutPromise;680 expectType<undefined>(ignoreStdoutResult.stdout);681 expectType<string>(ignoreStdoutResult.stderr);682 expectType<string>(ignoreStdoutResult.all);683684 const ignoreStderrPromise = execa('unicorns', {stderr: 'ignore', all: true});685 expectType<Writable>(ignoreStderrPromise.stdin);686 expectType<Writable>(ignoreStderrPromise.stdio[0]);687 expectType<Readable>(ignoreStderrPromise.stdout);688 expectType<Readable>(ignoreStderrPromise.stdio[1]);689 expectType<null>(ignoreStderrPromise.stderr);690 expectType<null>(ignoreStderrPromise.stdio[2]);691 expectType<Readable>(ignoreStderrPromise.all);692 expectError(ignoreStderrPromise.stdio[3].destroy());693 const ignoreStderrResult = await ignoreStderrPromise;694 expectType<string>(ignoreStderrResult.stdout);695 expectType<undefined>(ignoreStderrResult.stderr);696 expectType<string>(ignoreStderrResult.all);697698 const ignoreStdioPromise = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ignore'], all: true});699 expectType<Writable>(ignoreStdioPromise.stdin);700 expectType<Writable>(ignoreStdioPromise.stdio[0]);701 expectType<Readable>(ignoreStdioPromise.stdout);702 expectType<Readable>(ignoreStdioPromise.stdio[1]);703 expectType<Readable>(ignoreStdioPromise.stderr);704 expectType<Readable>(ignoreStdioPromise.stdio[2]);705 expectType<Readable>(ignoreStdioPromise.all);706 expectType<null>(ignoreStdioPromise.stdio[3]);707 const ignoreStdioResult = await ignoreStdioPromise;708 expectType<string>(ignoreStdioResult.stdout);709 expectType<string>(ignoreStdioResult.stderr);710 expectType<string>(ignoreStdioResult.all);711712 const inheritStdoutResult = await execa('unicorns', {stdout: 'inherit', all: true});713 expectType<undefined>(inheritStdoutResult.stdout);714 expectType<string>(inheritStdoutResult.stderr);715 expectType<string>(inheritStdoutResult.all);
3149 unmodified lines
modified:readme.md+126 added-41 removed
319 unmodified lines
320321Returns or throws a subprocess [`result`](#result). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available.322323The following features cannot be used:324- Streams: [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.readable()`](#subprocessreadablereadableoptions), [`subprocess.writable()`](#subprocesswritablewritableoptions), [`subprocess.duplex()`](#subprocessduplexduplexoptions).325- The [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [`stdio`](#optionsstdio) options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.326- Signal termination: [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`subprocess.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`cleanup`](#optionscleanup) option, [`cancelSignal`](#optionscancelsignal) option, [`forceKillAfterDelay`](#optionsforcekillafterdelay) option.324- Streams: [`subprocess.stdin`](#subprocessstdin), [`subprocess.stdout`](#subprocessstdout), [`subprocess.stderr`](#subprocessstderr), [`subprocess.readable()`](#subprocessreadablereadableoptions), [`subprocess.writable()`](#subprocesswritablewritableoptions), [`subprocess.duplex()`](#subprocessduplexduplexoptions).325- The [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [`stdio`](#optionsstdio) options cannot be [`'overlapped'`](#optionsstdout), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), nor a web stream. Node.js streams can be passed but only if either they [have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr), or the `input` option is used.326- Signal termination: [`subprocess.kill()`](#subprocesskillerror), [`subprocess.pid`](#subprocesspid), [`cleanup`](#optionscleanup) option, [`cancelSignal`](#optionscancelsignal) option, [`forceKillAfterDelay`](#optionsforcekillafterdelay) option.327- Piping multiple processes: [`subprocess.pipe()`](#subprocesspipefile-arguments-options).328- [`subprocess.iterable()`](#subprocessiterablereadableoptions).329- [`ipc`](#optionsipc) and [`serialization`](#optionsserialization) options.330- [`result.all`](#resultall) is not interleaved.
48 unmodified lines
379### subprocess380381The return value of all [asynchronous methods](#methods) is both:382- a `Promise` resolving or rejecting with a subprocess [`result`](#result).383- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties.383- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following methods and properties.384385#### subprocess.all386387Type: `ReadableStream | undefined`388389Stream [combining/interleaving](#ensuring-all-output-is-interleaved) [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).390391This is `undefined` if either:392- the [`all`](#optionsall) option is `false` (the default value)393- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)394385#### subprocess.pipe(file, arguments?, options?)386387`file`: `string | URL`\388`arguments`: `string[]`\
69 unmodified lines
458When 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).459460[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)461472#### subprocess[Symbol.asyncIterator]()462#### subprocess.pid463464_Type_: `number | undefined`465466Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).467468This is `undefined` if the subprocess failed to spawn.469470#### subprocess.send(message)471472`message`: `unknown`\473_Returns_: `boolean`474475Send a `message` to the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.476The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).477478This returns `true` on success.479480This requires the [`ipc`](#optionsipc) option to be `true`.481482[More info.](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback)483484#### subprocess.on('message', (message) => void)485486`message`: `unknown`487488Receives a `message` from the subprocess. The type of `message` depends on the [`serialization`](#optionsserialization) option.489The subprocess sends it using [`process.send(message)`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback).490491This requires the [`ipc`](#optionsipc) option to be `true`.492493[More info.](https://nodejs.org/api/child_process.html#event-message)494495#### subprocess.stdin496497Type: [`Writable | null`](https://nodejs.org/api/stream.html#class-streamwritable)498499The subprocess [`stdin`](#optionsstdin) as a stream.500501This is `null` if the [`stdin`](#optionsstdin) option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.502503This is intended for advanced cases. Please consider using the [`stdin`](#optionsstdin) option, [`input`](#optionsinput) option, [`inputFile`](#optionsinputfile) option, or [`subprocess.pipe()`](#subprocesspipefile-arguments-options) instead.504505#### subprocess.stdout506507Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)508509The subprocess [`stdout`](#optionsstdout) as a stream.510511This is `null` if the [`stdout`](#optionsstdout) option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`.512513This is intended for advanced cases. Please consider using [`result.stdout`](#resultstdout), the [`stdout`](#optionsstdout) option, [`subprocess.iterable()`](#subprocessiterablereadableoptions), or [`subprocess.pipe()`](#subprocesspipefile-arguments-options) instead.514515#### subprocess.stderr516517Type: [`Readable | null`](https://nodejs.org/api/stream.html#class-streamreadable)518519The subprocess [`stderr`](#optionsstderr) as a stream.520521This is `null` if the [`stderr`](#optionsstdout) option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`.522523This is intended for advanced cases. Please consider using [`result.stderr`](#resultstderr), the [`stderr`](#optionsstderr) option, [`subprocess.iterable()`](#subprocessiterablereadableoptions), or [`subprocess.pipe()`](#subprocesspipefile-arguments-options) instead.524525#### subprocess.all526527Type: [`Readable | undefined`](https://nodejs.org/api/stream.html#class-streamreadable)528529Stream [combining/interleaving](#ensuring-all-output-is-interleaved) [`subprocess.stdout`](#subprocessstdout) and [`subprocess.stderr`](#subprocessstderr).530531This is `undefined` if either:532- the [`all`](#optionsall) option is `false` (the default value).533- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`.534535This is intended for advanced cases. Please consider using [`result.all`](#resultall), the [`stdout`](#optionsstdout)/[`stderr`](#optionsstderr) option, [`subprocess.iterable()`](#subprocessiterablereadableoptions), or [`subprocess.pipe()`](#subprocesspipefile-arguments-options) instead.536537#### subprocess.stdio538539Type: [`[Writable | null, Readable | null, Readable | null, ...Array<Writable | Readable | null>]`](https://nodejs.org/api/stream.html#class-streamreadable)540541The subprocess `stdin`, `stdout`, `stderr` and [other files descriptors](#optionsstdio) as an array of streams.542543Each array item is `null` if the corresponding [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) or [`stdio`](#optionsstdio) option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`.544545This is intended for advanced cases. Please consider using [`result.stdio`](#resultstdio), the [`stdio`](#optionsstdio) option, [`subprocess.iterable()`](#subprocessiterablereadableoptions) or [`subprocess.pipe()`](#subprocesspipefile-arguments-options) instead.546547#### subprocess\[Symbol.asyncIterator\]()548549_Returns_: `AsyncIterable`550551Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.552
12 unmodified lines
565_Returns_: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) Node.js stream566567Converts the subprocess to a readable stream.568494Unlike [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), 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](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `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.569Unlike [`subprocess.stdout`](#subprocessstdout), 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](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `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.570571Before using this method, please first consider the [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr)/[`stdio`](#optionsstdio) options, [`subprocess.pipe()`](#subprocesspipefile-arguments-options) or [`subprocess.iterable()`](#subprocessiterablereadableoptions).572573#### subprocess.writable(writableOptions?)
2 unmodified lines
576_Returns_: [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) Node.js stream577578Converts the subprocess to a writable stream.579505Unlike [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin), 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](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.580Unlike [`subprocess.stdin`](#subprocessstdin), 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](#result). This means you do not need to `await` the subprocess' [promise](#subprocess). On the other hand, you do need to handle to the stream `error` event. This can be done by using [`await finished(stream)`](https://nodejs.org/api/stream.html#streamfinishedstream-options) or [`await pipeline(stream, ...)`](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options) which throw an exception when the stream errors.581582Before using this method, please first consider the [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr)/[`stdio`](#optionsstdio) options or [`subprocess.pipe()`](#subprocesspipefile-arguments-options).583584#### subprocess.duplex(duplexOptions?)
93 unmodified lines
678Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`679680The output of the subprocess on `stdout`.681607This is `undefined` if the [`stdout`](#optionsstdout) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This 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).682This is `undefined` if the [`stdout`](#optionsstdout) option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This 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).683684#### result.stderr685686Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`687688The output of the subprocess on `stderr`.689615This is `undefined` if the [`stderr`](#optionsstderr) option is set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This 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).690This is `undefined` if the [`stderr`](#optionsstderr) option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This 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).691692#### result.all693694Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`695621The output of the subprocess with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).696The output of the subprocess with [`result.stdout`](#resultstdout) and [`result.stderr`](#resultstderr) [interleaved](#ensuring-all-output-is-interleaved).697698This is `undefined` if either:624- the [`all`](#optionsall) option is `false` (the default value)625- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)699- the [`all`](#optionsall) option is `false` (the default value).700- both [`stdout`](#optionsstdout) and [`stderr`](#optionsstderr) options are set to only `'inherit'`, `'ignore'`, `Writable` or `integer`.701702This 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).703704#### result.stdio
1 unmodified line
706Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`707708The output of the subprocess on [`stdin`](#optionsstdin), [`stdout`](#optionsstdout), [`stderr`](#optionsstderr) and [other file descriptors](#optionsstdio).709635Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).710Items are `undefined` when their corresponding [`stdio`](#optionsstdio) option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`. Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).711712#### result.failed713714Type: `boolean`
232 unmodified lines
947Whether to return the subprocess' output using the [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) properties.948949On failure, the [`error.stdout`](#resultstdout), [`error.stderr`](#resultstderr), [`error.all`](#resultall) and [`error.stdio`](#resultstdio) properties are used instead.950876When `buffer` is `false`, the output can still be read using the [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.stdio`](https://nodejs.org/api/child_process.html#subprocessstdio) and [`subprocess.all`](#subprocessall) streams. If the output is read, this should be done right away to avoid missing any data.951When `buffer` is `false`, the output can still be read using the [`subprocess.stdout`](#subprocessstdout), [`subprocess.stderr`](#subprocessstderr), [`subprocess.stdio`](#subprocessstdio) and [`subprocess.all`](#subprocessall) streams. If the output is read, this should be done right away to avoid missing any data.952953#### options.input954955Type: `string | Uint8Array | stream.Readable`
14 unmodified lines
970971Type: `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)\972Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise973899[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:900- `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.974How to setup the subprocess' standard input. This can be:975- `'pipe'`: Sets [`subprocess.stdin`](#subprocessstdin) stream.976- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.977- `'ignore'`: Do not use `stdin`.978- `'inherit'`: Re-use the current process' `stdin`.979- an integer: Re-use a specific file descriptor from the current process.
7 unmodified lines
987This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.988989This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)990991[More info.](https://nodejs.org/api/child_process.html#child_process_options_stdio)992993#### options.stdout994995Type: `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)\996Default: `pipe`997921[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:922- `'pipe'`: Sets [`result.stdout`](#resultstdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).998How to setup the subprocess' standard output. This can be:999- `'pipe'`: Sets [`result.stdout`](#resultstdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](#subprocessstdout) (as a stream).1000- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.1001- `'ignore'`: Do not use `stdout`.1002- `'inherit'`: Re-use the current process' `stdout`.1003- an integer: Re-use a specific file descriptor from the current process.
5 unmodified lines
1009This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.10101011This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)10121013[More info.](https://nodejs.org/api/child_process.html#child_process_options_stdio)10141015#### options.stderr10161017Type: `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)\1018Default: `pipe`1019941[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:942- `'pipe'`: Sets [`result.stderr`](#resultstderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).1020How to setup the subprocess' standard error. This can be:1021- `'pipe'`: Sets [`result.stderr`](#resultstderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](#subprocessstderr) (as a stream).1022- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.1023- `'ignore'`: Do not use `stderr`.1024- `'inherit'`: Re-use the current process' `stderr`.1025- an integer: Re-use a specific file descriptor from the current process.
5 unmodified lines
1031This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.10321033This can also be a generator function, a [`Duplex`](docs/transform.md#duplextransform-streams) or a web [`TransformStream`](docs/transform.md#duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)10341035[More info.](https://nodejs.org/api/child_process.html#child_process_options_stdio)10361037#### options.stdio10381039Type: `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)\1040Default: `pipe`
3 unmodified lines
1044A single string can be used as a shortcut. For example, `{stdio: 'pipe'}` is the same as `{stdin: 'pipe', stdout: 'pipe', stderr: 'pipe'}`.10451046The array can have more than 3 items, to create additional file descriptors beyond `stdin`/`stdout`/`stderr`. For example, `{stdio: ['pipe', 'pipe', 'pipe', 'pipe']}` sets a fourth file descriptor.10471048[More info.](https://nodejs.org/api/child_process.html#child_process_options_stdio)10491050#### options.all10511052Type: `boolean`\1053Default: `false`
52 unmodified lines
11061107Type: `boolean`\1108Default: `true` if the [`node`](#optionsnode) option is enabled, `false` otherwise11091027Enables exchanging messages with the subprocess using [`subprocess.send(value)`](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [`subprocess.on('message', (value) => {})`](https://nodejs.org/api/child_process.html#event-message).1110Enables exchanging messages with the subprocess using [`subprocess.send(message)`](#subprocesssendmessage) and [`subprocess.on('message', (message) => {})`](#subprocessonmessage-message--void).11111112#### options.serialization11131114Type: `string`\1115Default: `'advanced'`11161117Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#optionsipc) option:1035 - `json`: Uses `JSON.stringify()` and `JSON.parse()`.1036 - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)1118- `json`: Uses `JSON.stringify()` and `JSON.parse()`.1119- `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)11201121[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)11221123#### options.detached11241125Type: `boolean`\1126Default: `false`11271045Prepare subprocess to run independently of the current process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).1128Prepare subprocess to run independently of the current process. Specific behavior depends on the platform.11291130[More info.](https://nodejs.org/api/child_process.html#child_process_options_detached).11311132#### options.cleanup11331134Type: `boolean`\1135Default: `true`11361137Kill the subprocess when the current process exits unless either:1053 - the subprocess is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)1054 - the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit1138- the subprocess is [`detached`](#optionsdetached).1139- the current process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit.11401141#### options.timeout11421143Type: `number`\
19 unmodified lines
1163The grace period is 5 seconds by default. This feature can be disabled with `false`.11641165This works when the subprocess is terminated by either:1166- the [`cancelSignal`](#optionscancelsignal), [`timeout`](#optionstimeout), [`maxBuffer`](#optionsmaxbuffer) or [`cleanup`](#optionscleanup) option1082- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments1167- calling [`subprocess.kill()`](#subprocesskillsignal-error) with no arguments11681169This does not work when the subprocess is terminated by either:1085- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with an argument1170- calling [`subprocess.kill()`](#subprocesskillsignal-error) with an argument1171- calling [`process.kill(subprocess.pid)`](https://nodejs.org/api/process.html#processkillpid-signal)1172- sending a termination signal from another process11731174Also, 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.
4 unmodified lines
1179Default: `SIGTERM`11801181Signal used to terminate the subprocess when:1182- using the [`cancelSignal`](#optionscancelsignal), [`timeout`](#optionstimeout), [`maxBuffer`](#optionsmaxbuffer) or [`cleanup`](#optionscleanup) option1098- calling [`subprocess.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal) with no arguments1183- calling [`subprocess.kill()`](#subprocesskillsignal-error) with no arguments11841185This can be either a name (like `"SIGTERM"`) or a number (like `9`).11861187#### options.argv0
50 unmodified lines
1238TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.1239```12401241This limitation can be worked around by passing either:1157 - a web stream ([`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream))1158 - `[nodeStream, 'pipe']` instead of `nodeStream`1242- a web stream ([`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream))1243- `[nodeStream, 'pipe']` instead of `nodeStream`12441245```diff1246- await execa(..., {stdout: nodeStream});1247+ await execa(..., {stdout: [nodeStream, 'pipe']});
90 unmodified lines