Created
July 31, 2019 21:34
-
-
Save raven-rock/b327a11246eef478688f6b79344ca6d3 to your computer and use it in GitHub Desktop.
Rescuing "Broken Pipe" errors in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If user pipes to less, or hits Ctrl-C, etc, avoid the annoying | |
# `Broken pipe @ io_writev - <STDOUT> (Errno::EPIPE)` error. | |
# Source: https://stackoverflow.com/questions/1807355/broken-pipe-errnoepipe/18082444#18082444 | |
ARGF.each do |line| | |
line.chomp! | |
begin | |
puts line | |
rescue Errno::EPIPE | |
exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment