Stderr / Stdio redirection

Is there a way in the new io API to easily redirect stderr / stdout?

Previously I was using std::old_io::PipeStream and std::old_io::pipe::PipePair. This is deprecated, though. So I went looking and found std::os::Pipe however that entire module is also deprecated, with the recommendation of using std::env instead, which does not provide an equivalent.

Is this an oversight? Or is there something else elsewhere that I'm missing?

For reference, the project I'm looking to update is: rustbox/ at master · gchp/rustbox · GitHub


What is that API trying to do?

For communicating with child process the std::proces has appropriate tools, but they are bound to the std::process::Command. For redirecting inside Rust, the undocumented std::io::stdio::set_print(sink: Box<Write + Send>) -> Option<Box<Write + Send>> can be used to redirect ouput of print!, though not other things that directly use std::io::stdout(). Depending on what the code actually does it may do what you need. Or not.

But generally for manipulating the filehandle 1 I don't think there is anything and don't think there will be anything before 1.0. The problem is that a way to do it in a reasonably system-agnostic way was not found yet.

If you need to do something and don't care about Windows — and the linked code contains comments about not working on Windows, so it might be fine — you should probably use the raw libc bindings in the libc crate. It's extra work, I know. I am about to do memory mapping with it that is also deprecated in std with no replacement in sight.