From: James Edward Gray II Date: 2005-06-07T04:40:09+09:00 Subject: Re: 'gets' has been hijacked On Jun 6, 2005, at 2:31 PM, Pete Elmore wrote: > I was working with a simple script, that unexpectedly broke. The > problem can be reduced to this: > > pete@robots:~$ cat t.rb > #!/usr/bin/env ruby > p gets > pete@robots:~$ ./t.rb > asdf > "asdf\n" > pete@robots:~$ ./t.rb nonexistent-file > ./t.rb:2:in `gets': No such file or directory - nonexistent-file > (Errno::ENOENT) > from ./t.rb:2 > > Ah, right, I remember this from the Bad Old Days of Perl: stdin has > been stolen. Is there any way to stop this behavior, like a global > I could set or a flag I could pass to ruby? Couldn't find anything > on the man page or in Pickaxe. gets() as you're using it calls Kernel.gets(), which basically amounts to ARGF.gets(). That's very handy for building Unix filters. If your intention is to read from the keyboard only, just make sure call gets() on STDIN with STDIN.gets() or $stdin.gets(). Hope that helps. James Edward Gray II