Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary applications and exiting pipes behave badly together by default #49025

Closed
clux opened this issue Mar 14, 2018 · 1 comment
Closed

binary applications and exiting pipes behave badly together by default #49025

clux opened this issue Mar 14, 2018 · 1 comment

Comments

@clux
Copy link

clux commented Mar 14, 2018

Consider an example program that produces a list to stdout, but takes some time doing so:

use std::{thread, time};

fn main() {
    let millis = time::Duration::from_millis(100);
    println!("a");
    thread::sleep(millis);
    println!("b");
    thread::sleep(millis);
    println!("c");
}
# works
./target/debug/piper | grep a
# crashes and shows me a rust backtrace
./target/debug/piper | grep -q a

The only related issue I found was #35108 which talks about using write! instead so you could handle the errors.

Sure enough, instead of println! using:

   let _ = io::stdout().write(b"a\n");

everywhere does fix it. But is this really a good substitute?

If we are writing CLI tools and are printing formatted strings to stdout we now have to start stuff like:

let _ = io::stdout().write(&format!("{}\n", svc).as_bytes());

which feels like a lot of faff for a "println that i don't care if the program i wrote into disappeared or not".

@sfackler
Copy link
Member

Duplicate of #46016

@sfackler sfackler marked this as a duplicate of #46016 Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants