Last active
December 22, 2015 00:58
-
-
Save thinkerbot/6392759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ruby/ruby/blob/trunk/io.c#L4023