This is a multi-part message in MIME format.

------extPart_000_000B_01C16401.B84A3360
Content-Type: text/plain;
	charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable

    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
rsilvergun / home.net


------extPart_000_000B_01C16401.B84A3360
Content-Type: text/html;
	charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; 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:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if fileName != nil 
then<BR>&nbsp;<BR>&nbsp;IO.readlines(fileName).each{|line|<BR>&nbsp;<BR>&nbsp;&nbsp;line.chomp!<BR>&nbsp;&nbsp;$lines 
&lt;&lt; line<BR>&nbsp;&nbsp;<BR>&nbsp;}#end 
IO.readlines...each<BR>&nbsp;&nbsp;<BR>end #if fileName<BR>&nbsp;&nbsp; 
<BR>while command = gets<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; print command</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>end #while</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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 O.readlines. I can fix this with an explicit $stdin.get, but that's kind of a 
hack. I can also throw in this code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>while trash = gets<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if fileName != nil then</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;inputFile&nbsp; = open 
fileName<BR>&nbsp;<BR>&nbsp;begin<BR>&nbsp;&nbsp;inputFile.each {|line| 
<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;line.chomp!<BR>&nbsp;&nbsp;&nbsp;$lines 
&lt;&lt; lline<BR>&nbsp;&nbsp;}#end 
inputFile.each<BR>&nbsp;&nbsp;<BR>&nbsp;ensure<BR>&nbsp;<BR>&nbsp;&nbsp;inputFile.close</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;end #end begin..ensure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>end #if<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>has the same problem. Can someone tell me what's 
going on here. I'm totally lost. Thanks again</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Jeremy Gregorio</FONT></DIV>
<DIV><FONT face=Arial size=2><A 
href="mailto:rsilvergun / home.net">rsilvergun / home.net</A></FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;</DIV></FONT></BODY></HTML>

------extPart_000_000B_01C16401.B84A3360--