#stdout #capture #stdio #process #stderr #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

Download history 83/week @ 2024-07-26 55/week @ 2024-08-02 3/week @ 2024-08-09 516/week @ 2024-08-16 705/week @ 2024-08-23 938/week @ 2024-08-30 386/week @ 2024-09-06 119/week @ 2024-09-13 55/week @ 2024-09-20 25/week @ 2024-09-27 18/week @ 2024-10-04 30/week @ 2024-10-11 49/week @ 2024-10-18 253/week @ 2024-10-25 558/week @ 2024-11-01

890 downloads per month

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–6.5MB
~35K SLoC