Created
May 1, 2012 02:48
-
-
Save knu/2564604 to your computer and use it in GitHub Desktop.
Pipe test
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 | |
pid = fork { | |
w.close | |
$stdin.reopen(r) | |
r.close | |
IO.select([$stdin], nil, [$stdin]) | |
exec 'more' | |
} | |
r.close | |
$stdout.reopen(w) | |
w.close | |
100.times { |i| | |
puts i | |
} | |
$stdout.flush | |
$stdout.close | |
# In Ruby 1.9+ this waits forever as "more" doesn't seem to get an EOF | |
Process.waitpid pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment