Command cannot replumb stdout to stderr #79731
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
When running a
Command
, it is often desirable to plumb stdout to the same place as stderr, as if2>&1
in a shell rune.Unfortunately, there is no way to do this with
Command
right now without writingunsafe
, non-portable code.Really we want to fix this so that you can pass to
Command
anything that implementsAsRawFd
, so probably the right thing would bestd::Process::Stdio::reuse<F:AsRawFd>(fd: &f)
. The implementation is not entirely trivial - we need an fd-permuting algorithm that avoids making unnecessary calls todup2
.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-transparentOsOpenFileReference
type andAsOsOpenFileReference
,IntoOsOpenFileReference
,FromOsOpenFileReference
but that seems like rather a major change.The text was updated successfully, but these errors were encountered: