Skip to content

Add {value: 'pipe', input: true} to use an additional file descriptor as input#1246

Merged
sindresorhus merged 1 commit into
mainfrom
fd-input-pipe
Jul 3, 2026
Merged

Add {value: 'pipe', input: true} to use an additional file descriptor as input#1246
sindresorhus merged 1 commit into
mainfrom
fd-input-pipe

Conversation

@sindresorhus

Copy link
Copy Markdown
Owner

For file dscriptors beyond stdin/stdout/stderr, 'pipe' is ambiguous: Execa cannot tell whether it is meant for input or output, so it defaults to output. This made it impossible to write into an extra file descriptor, e.g. .duplex({to: 'fd3'}), without the buggy ['pipe', []] workaround.

The new {value: 'pipe', input: true} object form explicitly marks such a file descriptor as input.

Fixes #1214

…or as input

For file descriptors beyond `stdin`/`stdout`/`stderr`, `'pipe'` is ambiguous: Execa cannot tell whether it is meant for input or output, so it defaults to output. This made it impossible to write into an extra file descriptor, e.g. `.duplex({to: 'fd3'})`, without the buggy `['pipe', []]` workaround.

The new `{value: 'pipe', input: true}` object form explicitly marks such a file descriptor as input.

Fixes #1214
@sindresorhus sindresorhus merged commit 487a3a4 into main Jul 3, 2026
20 checks passed
@sindresorhus sindresorhus deleted the fd-input-pipe branch July 3, 2026 08:06
Comment thread docs/api.md
A single string can be used [as a shortcut](output.md#shortcut).

The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr).
The array can have more than 3 items, to create [additional file descriptors](output.md#additional-file-descriptors) beyond [`stdin`](#optionsstdin)/[`stdout`](#optionsstdout)/[`stderr`](#optionsstderr). Passing `'pipe'` to an additional file descriptor defaults it to output. To use it for [input](input.md#additional-file-descriptors) instead, pass `{value: 'pipe', input: true}`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can only 'pipe' be ambiguous? For example, I would imagine 'inherit' could be possibly used for both input and output in fd3? Same with streams that are both readable and writable, or with files.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but I scoped it to 'pipe'/'overlapped' because that's what #1214 was about (the buggy ['pipe', []] workaround), but 'inherit' and files indeed share the same limitation. I'll look into it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only mentioning 'pipe' in the issue because that was the specific instance the user was experiencing, but the problem was more generic, in that it impacts other values.

I am actually wondering whether allowing any value would simplify the implementation, since some of the logic right now is making sure 'pipe' is used. Technically, some values do not make sense as input, namely 1, 2 or any non-readable stream (Node.js or web). But using fd3 + {input: true} + one of those values seems like such an edge case, which is going to fail runtime anyway, that it might not deserve any safeguard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using duplex() with fd3: it must be a writable stream

2 participants