Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Error when reading file from command prompt

Reply
Thread Tools

Error when reading file from command prompt

 
 
Mmcolli00 Mom
Guest
Posts: n/a
 
      04-22-2009
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-forum.com/.

 
Reply With Quote
 
 
 
 
Suresh Kk
Guest
Posts: n/a
 
      04-22-2009
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-forum.com/.

 
Reply With Quote
 
 
 
 
Jesús Gabriel y Galán
Guest
Posts: n/a
 
      04-22-2009
On Wed, Apr 22, 2009 at 6:02 PM, Mmcolli00 Mom <(E-Mail Removed)> 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.

 
Reply With Quote
 
Alan Claughan
Guest
Posts: n/a
 
      04-22-2009
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'



 
Reply With Quote
 
Alan Claughan
Guest
Posts: n/a
 
      04-22-2009
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'

>
>



 
Reply With Quote
 
Mmcolli00 Mom
Guest
Posts: n/a
 
      04-22-2009
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-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javac command not working in command prompt chrisdude911 Java 10 03-10-2009 09:55 AM
prompt to save on exit - disable prompt on save button Mel ASP .Net 10 02-13-2009 05:32 AM
How to open a shell prompt from an existing shell prompt gaurav kashyap Python 3 10-31-2008 04:41 AM
How to open a shell prompt from an existing shell prompt gaurav kashyap Python 2 10-30-2008 09:18 AM
Access Denied when i type command at command prompt calvin MCDST 0 03-08-2006 06:33 AM



Advertisments