Newbie question

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?

Regards,

Heitor Faria
www.bacula.com.br

Hi Heitor,

On Tue, 2009-06-16 at 07:21 -0700, Heitor Faria wrote:

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?

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üë” [email protected]

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 Tue, 2009-06-16 at 10:31 -0700, Heitor Faria wrote:

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

On Tue, 2009-06-16 at 11:05 -0700, Heitor Faria wrote:

Gee… Im really a newbie… =P

We all were. Welcome aboard!

Best regards,
Bill

Gee… Im really a newbie… =P

ruby p004stringusage.rb

In which city do you stay?
salvador
The city is salvador