# Newbie - Q: working with files

**URL:** <https://www.ruby-forum.com/t/newbie-q-working-with-files/99109>\
**Category:** Ruby\
**Created:** [July 20, 2006, 10:37am UTC](https://www.ruby-forum.com/t/newbie-q-working-with-files/99109 "2006-07-20T10:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [July 20, 2006, 10:37am UTC](https://www.ruby-forum.com/t/newbie-q-working-with-files/99109/1 "2006-07-20T10:37:23Z")

</div>

Hi,

I have a function with the following code

def first\_parse  
@in\_file.each\_line do |line|  
puts line  
@line += 1;  
tokens = line.split  
handle\_command(tokens, line)  
end  
puts “End of file reached”  
@heap.dump(@obj\_file)  
end

The problem is that I parse the entire file (@in\_file), and my app  
exits, but I never execute the puts “End of file reached”. Anyone have  
any ideas why?

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [July 20, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/newbie-q-working-with-files/99109/2 "2006-07-20T14:44:58Z")

</div>

On Jul 20, 2006, at 4:37 AM, Allison N. wrote:

> end  
> puts “End of file reached”  
> @heap.dump(@obj\_file)  
> end
> 
> The problem is that I parse the entire file (@in\_file), and my app  
> exits, but I never execute the puts “End of file reached”. Anyone  
> have  
> any ideas why?

I would wonder if something’s happening in handle\_command. Or maybe  
there’s an output buffering problem going on. You could try  
‘$stdout.sync = true’. But this is all just blind guessing.  
-Mat

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [July 20, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/newbie-q-working-with-files/99109/3 "2006-07-20T19:24:43Z")

</div>

> ```
> handle_command(tokens, line)
> 
> ```
> 
> end  
> puts “End of file reached”  
> @heap.dump(@obj\_file)  
> end
> 
> The problem is that I parse the entire file (@in\_file), and my app  
> exits, but I never execute the puts “End of file reached”. Anyone have  
> any ideas why?

Maybe something is going wrong in your handle\_command call that makes  
the program exit without finishing. Make sure you are running ruby with  
warnings on and that might help a little.

Tait P.
