[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Error when reading file from command prompt

Mmcolli00 Mom

4/22/2009 4:02:00 PM

Hi. I have a program that is supposed to get a filename at the command
prompt. It reads in the input ok but doesn't initialize to the file. I
have more code that takes the file and parses it but I did not paste
that below.

Question: Is there a step that I am missing in f = File.new(myinput)?
Thanks MC

inputFile = print("Enter Filename: ")
$stdout.flush
input = gets
myinput = input.to_s

f = File.new(myinput) <-- in 'initialize': Invalid argument - filename
(Errno::EINAL) from crb.rb in 'new'
--
Posted via http://www.ruby-....

5 Answers

Suresh Kk

4/22/2009 4:11:00 PM

0

Mmcolli00 Mom wrote:
> Hi. I have a program that is supposed to get a filename at the command
> prompt. It reads in the input ok but doesn't initialize to the file. I
> have more code that takes the file and parses it but I did not paste
> that below.
>
> Question: Is there a step that I am missing in f = File.new(myinput)?
> Thanks MC
>
> inputFile = print("Enter Filename: ")
> $stdout.flush
> input = gets
> myinput = input.to_s
>
> f = File.new(myinput) <-- in 'initialize': Invalid argument - filename
> (Errno::EINAL) from crb.rb in 'new'

input = gets

input = gets.chomp
--
Posted via http://www.ruby-....

Jesús Gabriel y Galán

4/22/2009 4:12:00 PM

0

On Wed, Apr 22, 2009 at 6:02 PM, Mmcolli00 Mom <mmc_collins@yahoo.com> wrote:
> Hi. I have a program that is supposed to get a filename at the command
> prompt. It reads in the input ok but doesn't initialize to the file. I
> have more code that takes the file and parses it but I did not paste
> that below.
>
> Question: Is there a step that I am missing in f = File.new(myinput)?
> Thanks MC
>
> inputFile = print("Enter Filename: ")
> $stdout.flush
> input = gets

Try:

input = gets.chomp

gets is returning the \n at the end of the string.

> myinput = input.to_s
>
> f = File.new(myinput) <-- in 'initialize': Invalid argument - filename
> (Errno::EINAL) from crb.rb in 'new'

Jesus.

Alan Claughan

4/22/2009 7:50:00 PM

0

Wow you seem to be a little confused her

in line 1 you try to get a inputFile name from a print statement.

You actually get the filename with line 3.

line 4 is unnecessary as gets returns a string anyway.

So you can do :

puts 'Enter Filename: '
$stdout.flush
filename = gets.chomp

inputfile = File.new(filename, 'w')

Alan.

On 22 Apr 2009, at 6:02 PM, Mmcolli00 Mom wrote:

> inputFile = print("Enter Filename: ")
> $stdout.flush
> input = gets
> myinput = input.to_s
>
> f = File.new(myinput) <-- in 'initialize': Invalid argument - filename
> (Errno::EINAL) from crb.rb in 'new'


Alan Claughan

4/22/2009 7:54:00 PM

0

Oops that should be :

puts 'Enter Filename: '
$stdout.flush
filename = gets.chomp

inputfile = File.new(filename, 'r')

:-)



On 22 Apr 2009, at 9:49 PM, Alan Claughan wrote:

> Wow you seem to be a little confused her
>
> in line 1 you try to get a inputFile name from a print statement.
>
> You actually get the filename with line 3.
>
> line 4 is unnecessary as gets returns a string anyway.
>
> So you can do :
>
> puts 'Enter Filename: '
> $stdout.flush
> filename = gets.chomp
>
> inputfile = File.new(filename, 'w')
>
> Alan.
>
> On 22 Apr 2009, at 6:02 PM, Mmcolli00 Mom wrote:
>
>> inputFile = print("Enter Filename: ")
>> $stdout.flush
>> input = gets
>> myinput = input.to_s
>>
>> f = File.new(myinput) <-- in 'initialize': Invalid argument -
>> filename
>> (Errno::EINAL) from crb.rb in 'new'
>
>


Mmcolli00 Mom

4/22/2009 9:03:00 PM

0

Alan Claughan wrote:
> Oops that should be :
>
> puts 'Enter Filename: '
> $stdout.flush
> filename = gets.chomp
>
> inputfile = File.new(filename, 'r')
>
> :-)

thanks!
--
Posted via http://www.ruby-....