Some problems with file IO in the winruby... 
Author Message
 Some problems with file IO in the winruby...

    I installed winruby a while back. I've been using ruby from the command line like so: ruby my_prog.rb and so far it's worked great, but I came across something I can't figure out. I tried this code:

if fileName != nil then

 IO.readlines(fileName).each{|line|

  line.chomp!
  $lines << line

 }#end IO.readlines...each

end #if fileName

while command = gets

    print command

end #while

Ideally it should read the contents of a file whose name I specify on the command line and then prompt the user for input and print that input. but the calls to gets are going to the file object opened by IO.readlines. I can fix this with an explicit $stdin.get, but that's kind of a hack. I can also throw in this code:

while trash = gets
end

and it consumes the file object from IO.readlines and lets me get on with reading from standard input. But again that's a hack. Is there some way to force gets() back to reading from standard input. i.e. to properly close out the file. I thought Using File.new and then explictly closing the object it returns would do that, but this code:

if fileName != nil then

 inputFile  = open fileName

 begin
  inputFile.each {|line|

   line.chomp!
   $lines << lline
  }#end inputFile.each

 ensure

  inputFile.close

 end #end begin..ensure

end #if

has the same problem. Can someone tell me what's going on here. I'm totally lost. Thanks again

Jeremy Gregorio



Thu, 22 Apr 2004 03:47:05 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. File IO problem

2. Newbie: Problems with File IO

3. file io with verilog, reading file into a reg

4. DATA and ARGV don't seem to work under winruby

5. mixing IO#read and IO#syswrite

6. Perl IO to Ruby IO help needed

7. IMPORT IO, FROM IO IMPORT ?

8. IMPORT IO, FROM IO IMPORT ?

9. IMPORT IO, FROM IO IMPORT ?

10. BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

11. BUG? IO.seek conflicts with IO.sysread

12. VAX Ada sequential IO and Direct IO - (nf)

 

 
Powered by phpBB® Forum Software