Skip to content

Instantly share code, notes, and snippets.

@raven-rock
Created July 31, 2019 21:34
Show Gist options
  • Save raven-rock/b327a11246eef478688f6b79344ca6d3 to your computer and use it in GitHub Desktop.
Save raven-rock/b327a11246eef478688f6b79344ca6d3 to your computer and use it in GitHub Desktop.
Rescuing "Broken Pipe" errors in Ruby
# 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