Skip to content

Instantly share code, notes, and snippets.

@knu
Created May 1, 2012 02:48
Show Gist options
  • Save knu/2564604 to your computer and use it in GitHub Desktop.
Save knu/2564604 to your computer and use it in GitHub Desktop.
Pipe test
#!/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