Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Last active December 22, 2015 00:58
Show Gist options
  • Save thinkerbot/6392759 to your computer and use it in GitHub Desktop.
Save thinkerbot/6392759 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
r, w = IO.pipe
# exec on ruby 2.0 closes the fds and so cat fails with "Bad file descriptor"
# on ree this works as expected.
#
# I thought close_on_exec was the issue, but this doesn't fix it at all.
# Perhaps it is not being respected?
#
# r.close_on_exec = false
# w.close_on_exec = false
#
# Maybe related:
# * https://www.ruby-forum.com/topic/566695
#
if Process.fork
r.close
w.puts "echo hello"
w.close
else
w.close
exec "cat <&#{r.fileno}"
end
@cschneid
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment