The default Rust runtime panics when println!
and family write to a closed
pipe. sigpipe
fixes it with a single function call invoked at the start of your program.
fn main() {
sigpipe::reset();
// The rest of your program goes here.
}
# Using cargo-edit
cargo add sigpipe
# In your Cargo.toml
[dependencies]
sigpipe = "0.1"
There have been several discussions about this issue. See:
This library is directly copied from @burntsushi's StackOverflow answer.
I made this library to package the solution, so users don't have to hunt for it online.