Running this: # p005methods.rb # gets and chomp puts "In which city do you stay?" STDOUT.flush city = gets.chomp puts "The city is " + city I get this:>ruby p004stringusage.rbIn which city do you stay? p004stringusage.rb:5:in `gets'': Bad file descriptor (Errno::EBADF) from p004stringusage.rb:5>Exit code: 1What is whrong? Regards, Heitor Faria www.bacula.com.br
Hi Heitor, On Tue, 2009-06-16 at 07:21 -0700, Heitor Faria wrote:> Running this: > > # p005methods.rb > # gets and chomp > puts "In which city do you stay?" > STDOUT.flush > city = gets.chomp > puts "The city is " + city > > I get this: > > >ruby p004stringusage.rb > In which city do you stay? > p004stringusage.rb:5:in `gets'': Bad file descriptor (Errno::EBADF) > from p004stringusage.rb:5 > >Exit code: 1 > > What is whrong?The problem is with ''gets''. Not sure what OS you''re on, but it works on both Ubuntu and Windows in IRB. Could be a problem with how your system has mapped STDIN. HTH, Bill
Agree with Bill.. I tested this in IRB and it works fine.. What OS are you using? -- Posted via http://www.ruby-forum.com/.
Im using Ubuntu 8.0. On irb, the "gets" works - but not on that script Im running using the SciTE editor. On 16 jun, 13:09, "Älphä Blüë" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Agree with Bill.. > > I tested this in IRB and it works fine.. What OS are you using? > > -- > Posted viahttp://www.ruby-forum.com/.
On Tue, 2009-06-16 at 09:26 -0700, Heitor Faria wrote:> Im using Ubuntu 8.0. > On irb, the "gets" works - but not on that script Im running using the > SciTE editor.What do you mean "running using the SciTE editor"? What happens when you run the script from the command line? Bill
On command line seems ok: # p005methods.rb # gets and chomp puts "In which city do you stay?" In which city do you stay? => nil STDOUT.flush => #<IO:0xb7c72f74> city = gets.chomp salvador => "puts \"The city is \" + citysalvador" On 16 jun, 13:48, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, 2009-06-16 at 09:26 -0700, Heitor Faria wrote: > > Im using Ubuntu 8.0. > > On irb, the "gets" works - but not on that script Im running using the > > SciTE editor. > > What do you mean "running using the SciTE editor"? > > What happens when you run the script from the command line? > > Bill
On Tue, 2009-06-16 at 10:31 -0700, Heitor Faria wrote:> On command line seems ok: > > # p005methods.rb > # gets and chomp > puts "In which city do you stay?" > In which city do you stay? > => nil > STDOUT.flush > => #<IO:0xb7c72f74> > city = gets.chomp > salvador > => "puts \"The city is \" + citysalvador"That''s either irb or script/console. I meant run the script from the command line. ruby p005methods.rb
Gee... Im really a newbie... =P # ruby p004stringusage.rb In which city do you stay? salvador The city is salvador On 16 jun, 14:50, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, 2009-06-16 at 10:31 -0700, Heitor Faria wrote: > > On command line seems ok: > > > # p005methods.rb > > # gets and chomp > > puts "In which city do you stay?" > > In which city do you stay? > > => nil > > STDOUT.flush > > => #<IO:0xb7c72f74> > > city = gets.chomp > > salvador > > => "puts \"The city is \" + citysalvador" > > That''s either irb or script/console. I meant run the script from the > command line. > > ruby p005methods.rb