Last active
November 19, 2017 23:04
-
-
Save dcki/76d4acf3db308616a210945f16c41e30 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
| # Example: ruby read_multiple_streams.rb a <(for x in $(seq 10); do echo $x; sleep 1; done) <(echo bs98dfh8dhf9dshfdshf9shdf98shd98fshd98fhs98fhds) asdf <(sleep 2; echo ababababababababababababababababababababab) | |
| io_objects = [] | |
| ARGV.each do |arg| | |
| if arg =~ /^\/dev\/fd\/[0-9]+$/ | |
| io_objects << IO.new(IO.sysopen(arg)) | |
| end | |
| end | |
| ARGV.clear | |
| io_objects.delete_if {|io| io.eof? } | |
| until io_objects.empty? do | |
| ready_io_objects = IO.select(io_objects)[0] | |
| ready_io_objects.each do |io| | |
| puts io.read_nonblock 10 | |
| end | |
| io_objects.delete_if {|io| io.eof? } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment