From: Alex Young Date: 2006-08-06T16:57:14+09:00 Subject: Re: How to redirect a string to stdin within code? Robert Dober wrote: >> alex@pandora:~$ irb >> irb(main):001:0> require 'stringio' >> => true >> irb(main):002:0> input = StringIO.new("myname") >> => # >> irb(main):003:0> $stdin = input >> => # >> /usr/lib/ruby/1.8/irb/input-method.rb:97: [BUG] Segmentation fault >> ruby 1.8.4 (2005-12-24) [i486-linux] >> >> Aborted >> >> >> This is on Ubuntu Breezy. Any idea why that happens? > > > Very interesting I was just trying it on my Dapper and I get similar but > not identical behavior, see below. > However this seems an IRB issue Logans code just works fine in pure ruby Yes... I can see why it's not allowed in IRB (if you get rid of stdin, how the hell would you use the console? :-), I just don't know why it segfaults. > > 510/11 > irb > irb(main):001:0> require 'stringio' > => true > irb(main):002:0> input = StringIO.new("myname") > => # > irb(main):003:0> $stdin = input > => # > irb(main):004:0> irb(main):004:0> NameError: undefined local variable or > method `myname' for main:Object > from (irb):4 > from :0 > irb(main):004:0> robert@:~/log/ruby/tests 09:43:16 > > and > > 510/12 > uname -a > Linux roma 2.6.15-19-386 #1 PREEMPT Mon Mar 20 16:46:02 UTC 2006 i686 > GNU/Linux > robert@:~/log/ruby/tests 09:45:04 > 511/13 > ruby --version > ruby 1.8.4 (2005-12-24) [i686-linux] Interesting. In principle, we should get the same results - the only difference is the target processor. Allegedly. -- Alex