Skip to content
Myr

Document how to pass a Node.js stream to stdin/stdout/stderr (#644)

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

authored by ehmicky · committed by GitHub · parent 7efd50c · Browse files · 2 files+23 added−6 removed
This commit

State

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

Diff stats

2 files+23 added−6 removed

  • other:+23 added−6 removed

2 files+23 added−6 removed

modified:index.d.ts+3 added-3 removed
115 unmodified lines
116 - `'ignore'`: Do not use `stdin`.117 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.118 - `'inherit'`: Re-use the current process' `stdin`.119 - an integer: Re-use a specific file descriptor from the current process.120 - a Node.js `Readable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.120 - a Node.js `Readable` stream.121122 Unless either the synchronous methods, the `input` option or the `inputFile` option is used, the value can also be a:123 - file path. If relative, it must start with `.`.124 - file URL.
13 unmodified lines
138 - `'ignore'`: Do not use `stdout`.139 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.140 - `'inherit'`: Re-use the current process' `stdout`.141 - an integer: Re-use a specific file descriptor from the current process.142 - a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.142 - a Node.js `Writable` stream.143144 Unless either synchronous methods, the value can also be a:145 - file path. If relative, it must start with `.`.146 - file URL.
12 unmodified lines
159 - `'ignore'`: Do not use `stderr`.160 - `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use `execaNode()` instead.161 - `'inherit'`: Re-use the current process' `stderr`.162 - an integer: Re-use a specific file descriptor from the current process.163 - a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.163 - a Node.js `Writable` stream.164165 Unless either synchronous methods, the value can also be a:166 - file path. If relative, it must start with `.`.167 - file URL.
915 unmodified lines
modified:readme.md+20 added-3 removed
577 unmodified lines
578- `'ignore'`: Do not use `stdin`.579- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.580- `'inherit'`: Re-use the current process' `stdin`.581- an integer: Re-use a specific file descriptor from the current process.582- a Node.js `Readable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.582- a [Node.js `Readable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).583584Unless either the [synchronous methods](#execasyncfile-arguments-options), the [`input` option](#input) or the [`inputFile` option](#inputfile) is used, the value can also be a:585- file path. If relative, it must start with `.`.586- file URL.
13 unmodified lines
600- `'ignore'`: Do not use `stdout`.601- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.602- `'inherit'`: Re-use the current process' `stdout`.603- an integer: Re-use a specific file descriptor from the current process.604- a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.604- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).605606Unless either [synchronous methods](#execasyncfile-arguments-options), the value can also be a:607- file path. If relative, it must start with `.`.608- file URL.
12 unmodified lines
621- `'ignore'`: Do not use `stderr`.622- `'ipc'`: Sets an [IPC channel](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). You can also use [`execaNode()`](#execanodescriptpath-arguments-options) instead.623- `'inherit'`: Re-use the current process' `stderr`.624- an integer: Re-use a specific file descriptor from the current process.625- a Node.js `Writable` stream. It must have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules.625- a [Node.js `Writable` stream](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr).626627Unless either [synchronous methods](#execasyncfile-arguments-options), the value can also be a:628- file path. If relative, it must start with `.`.629- file URL.
191 unmodified lines
821```822823When combining `inherit` with other values, please note that the child process will not be an interactive TTY, even if the parent process is one.824825### Redirect a Node.js stream from/to stdin/stdout/stderr826827When passing a Node.js stream to the [`stdin`](#stdin), [`stdout`](#stdout-1) or [`stderr`](#stderr-1) option, Node.js requires that stream to have an underlying file or socket, such as the streams created by the `fs`, `net` or `http` core modules. Otherwise the following error is thrown.828829```830TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stdio' is invalid.831```832833This limitation can be worked around by passing either:834 - 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))835 - `[nodeStream, 'pipe']` instead of `nodeStream`836837```diff838- await execa(..., { stdout: nodeStream })839+ await execa(..., { stdout: [nodeStream, 'pipe'] })840```841842### Retry on error843844Gracefully handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:845
84 unmodified lines