[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rake dies on "gets"

Its Me

5/2/2006 6:41:00 PM

This rakefile:
-----------------
# require 'rake'

def foobar
i = 0
puts "#{i.to_s}: enter> "
i = gets.to_i
end

desc "foo will foo"
task :foo do
foobar
end

-----------------
dies thusly in "gets":

C:>rake foo -t
(in C:/)
** Invoke foo (first_time)
** Execute foo
0: enter>
rake aborted!
No such file or directory - foo
C:/rakefile.rb:6:in `gets'
C:/rakefile.rb:6:in `foobar'
.....


A bug? Using 0.7.1



4 Answers

Ross Bamford

5/2/2006 6:53:00 PM

0

On Tue, 02 May 2006 19:40:45 +0100, itsme213 <itsme213@hotmail.com> wrote:

> This rakefile:
> -----------------
> # require 'rake'
>
> def foobar
> i = 0
> puts "#{i.to_s}: enter> "
> i = gets.to_i
> end
>
> desc "foo will foo"
> task :foo do
> foobar
> end
>
> -----------------
> dies thusly in "gets":
>
> C:>rake foo -t
> (in C:/)
> ** Invoke foo (first_time)
> ** Execute foo
> 0: enter>
> rake aborted!
> No such file or directory - foo
> C:/rakefile.rb:6:in `gets'
> C:/rakefile.rb:6:in `foobar'
> ....
>
>
> A bug? Using 0.7.1
>

Kernel#gets behaves differently in different situations (it basically
reads ARGF which may or may not be stdin - here it's a file 'foo'. See
docs for more details). I find it's usually best (especially in embedded
ruby, such as a Rakefile) to go for an explicit $stdin.gets. Try switch
ing the input line for:

i = $stdin.gets.to_i

Hope that helps,
--
Ross Bamford - rosco@roscopeco.remove.co.uk

Its Me

5/2/2006 7:32:00 PM

0


"Ross Bamford" <rosco@roscopeco.remove.co.uk> wrote in message
> Kernel#gets behaves differently in different situations (it basically
> reads ARGF which may or may not be stdin - here it's a file 'foo'. See
> docs for more details). I find it's usually best (especially in embedded
> ruby, such as a Rakefile) to go for an explicit $stdin.gets. Try switch
> ing the input line for:
>
> i = $stdin.gets.to_i
>
> Hope that helps,

It does fix this failure, thanks a bunch!

(though I don't believe rake should make it think it's reading a file 'foo')


Ross Bamford

5/3/2006 11:27:00 AM

0

On Tue, 02 May 2006 20:32:19 +0100, itsme213 <itsme213@hotmail.com> wrote:

>
> "Ross Bamford" <rosco@roscopeco.remove.co.uk> wrote in message
>> Kernel#gets behaves differently in different situations (it basically
>> reads ARGF which may or may not be stdin - here it's a file 'foo'. See
>> docs for more details). I find it's usually best (especially in embedded
>> ruby, such as a Rakefile) to go for an explicit $stdin.gets. Try switch
>> ing the input line for:
>>
>> i = $stdin.gets.to_i
>>
>> Hope that helps,
>
> It does fix this failure, thanks a bunch!
>
> (though I don't believe rake should make it think it's reading a file
> 'foo')
>

It's not a rake-specific thing, it's just the way Kernel#gets works in
ruby:

$ ruby -e 'puts gets'
No filename given, I had to type this in
No filename given, I had to type this in

$ ruby -e 'puts gets' index.html
<?xml version="1.0" encoding="iso-8859-1"?>

The reason I mentioned embedded usage is because often you have no control
over how the commandline is used there, so gets can seem to behave quite
arbitrarily since you can't see what's actually happening.

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Its Me

5/4/2006 1:49:00 PM

0


"Ross Bamford" <rosco@roscopeco.remove.co.uk> wrote in message

> The reason I mentioned embedded usage is because often you have no control
> over how the commandline is used there, so gets can seem to behave quite
> arbitrarily since you can't see what's actually happening.

Ah, I get it. Thanks for the explanation.