Skip to content

Instantly share code, notes, and snippets.

@sneakin
Created October 17, 2011 13:12
Show Gist options
  • Save sneakin/1292579 to your computer and use it in GitHub Desktop.
Save sneakin/1292579 to your computer and use it in GitHub Desktop.
jRuby IO.select fail
# This should print "nada" unless stdin has data.
while true
i, o, e = IO.select([$stdin], nil, nil, 0)
if i.include?($stdin)
c = $stdin.readpartial(1024)
puts c.inspect
else
puts "nada"
end
end
@BanzaiMan
Copy link

At the beginning of the execution of this script, there is nothing in $stdin, so this script block on line 7.

If you feed some stuff on $stdin in the beginning, the script will terminate as expected. For example:

[system] gist1292579-ecd3acd88097b7404b1e1b3faae8bfcecad2e8cd [git:master] $ echo "blah" | jruby gistfile1.rb 
"blah\n"
EOFError: End of file reached
  readpartial at org/jruby/RubyIO.java:2533
       (root) at gistfile1.rb:7

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