#capture #stdio #process #stderr #stdout #stdin #output

nightly capture-stdio

Capture stdin/out/err of the current process

2 releases

0.1.1 Aug 13, 2022
0.1.0 Aug 13, 2022

#26 in #stderr

MIT license

10KB
237 lines

capture-stdio

Rust crate to capture stdin/stdout/stderr of the current process.


lib.rs:

This crate provide some helper functions to capture the stdin/out/err of the current process to help mocking.

In testing, cargo test capture the stdout/err via std::io::set_output_capture. We can use the same mechanism to intercept [print!] and [eprint!] output. The crate wraps the call in [OutputCapture] so that you can intercept the output easily.

The crate also implements a pipe-then-dup method to intercept stdio. In detail, it creates a pipe and replaces the fd of stdio. You can use [PipedStdin] to intercept stdin, use [PipedStdout] for stdout and [PipedStderr] for stderr.

Dependencies

~0–8.5MB
~47K SLoC