dropping user to IRB after reading from pipe
- by aurelian
I have this script that drops the user to an IRB session when executed.
All good, but when I use *nix pipes to get the input (e.g. with cat), the IRB session ends immediately.
I could reduce the script (let's call it myscript.rb) to the following:
require 'irb'
if $stdin.stat.size 0
@text = $stdin.read
else
@text= "nothing"
end
ARGV.clear
IRB.start
When executed like: ruby myscript.rb, I end up in the IRB session (as expected).
But (assuming foo.txt exists in the cwd): cat foo.txt | ruby myscript.rb will just print the IRB prompt and then the IRB session is closed (I'm being dropped to $bash).
Any known workarounds or ideas?
BTW: it has the same behavior on ruby 1.8.7 as well as on 1.9.2.