Exit gracefully on broken pipe, fixes #24

This commit is contained in:
sharkdp 2017-06-07 23:58:08 +02:00
parent 641ca69b49
commit 2ea23c0000

View file

@ -138,12 +138,16 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
}
println!();
} else {
// Uncolorized output:
// Uncolorized output
if config.path_display == PathDisplay::Absolute {
print!("{}", ROOT_DIR);
let prefix = if config.path_display == PathDisplay::Absolute { ROOT_DIR } else { "" };
let r = writeln!(&mut std::io::stdout(), "{}{}", prefix, path_str);
if r.is_err() {
// Probably a broken pipe. Exit gracefully.
process::exit(0);
}
println!("{}", path_str);
}
}