dropping user to IRB after reading from pipe
Posted
by
aurelian
on Stack Overflow
See other posts from Stack Overflow
or by aurelian
Published on 2011-01-03T14:36:25Z
Indexed on
2011/01/03
14:53 UTC
Read the original article
Hit count: 237
ruby
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.
© Stack Overflow or respective owner