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

Broken pipe error when piping the output to head #2

Closed
miikka opened this issue Oct 9, 2018 · 5 comments
Closed

Broken pipe error when piping the output to head #2

miikka opened this issue Oct 9, 2018 · 5 comments

Comments

@miikka
Copy link

miikka commented Oct 9, 2018

Hey, I just used wf for some data exploration and it was pretty useful! I tried to look up the most frequent word in a text and piped wf's output to head. I got the following error message. The error probably happens because head exits after it has printed the requested number of lines. I would expect a command-line tool like wf to handle piping to head gracefully.

% wf -f < text.txt | head -1
the 2228
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', libstd/io/stdio.rs:692:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I'm using wf 0.2.0 on macOS.

@jarcane
Copy link
Owner

jarcane commented Oct 9, 2018

Hmm. That is odd. I don't have a Mac anymore to try this, but I can mess about on WSL.

Out of curiosity, what do you get if instead you do cat text.txt | wf -f | head -1?

@miikka
Copy link
Author

miikka commented Oct 10, 2018

It gives me the same error. I googled a bit and turns out other people are having the same problem: rust-lang/rust#46016

@jarcane
Copy link
Owner

jarcane commented Oct 10, 2018

OK, thanks. I'll try and have a look at that tonight. Looks like there might be a work around using write! instead of println!.

@jarcane
Copy link
Owner

jarcane commented Oct 13, 2018

I've pushed a new version 0.2.1 that fixes the bug by adding the necessary error checking and early exit behavior with writeln!.

You can run cargo install wf --force to update.

@miikka
Copy link
Author

miikka commented Oct 15, 2018

Thanks! It works now.

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