Skip to content

Command cannot replumb stdout to stderr #79731

Closed
@ijackson

Description

@ijackson

When running a Command, it is often desirable to plumb stdout to the same place as stderr, as if 2>&1 in a shell rune.

Unfortunately, there is no way to do this with Command right now without writing unsafe, non-portable code.

Really we want to fix this so that you can pass to Command anything that implements AsRawFd, so probably the right thing would be std::Process::Stdio::reuse<F:AsRawFd>(fd: &f). The implementation is not entirely trivial - we need an fd-permuting algorithm that avoids making unnecessary calls to dup2.

On Windows that would be std::Process::Stdio::reuse<F:AsRawHandle>(fd: &f) I guess.

It's a shame that we have totally separate names for *RawFd and *RawHandle rather than a portable-opaque but nonportably-transparent OsOpenFileReference type and AsOsOpenFileReference, IntoOsOpenFileReference, FromOsOpenFileReference but that seems like rather a major change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions