title: How to read an open file in Ruby
body: <p>I want to be able to read a currently open file. The test.rb is sending its output to test.log which I want to be able to read and ultimately send via email.</p>
  
  <p>I am running this using cron:</p>
  
  <pre><code>*/5 * * * /tmp/test.rb &gt; /tmp/log/test.log 2&gt;&amp;1
  </code></pre>
  
  <p>I have something like this in test.rb:</p>
  
  <pre><code>#!/usr/bin/ruby
  
  def read_file(file_name)
    file = File.open(file_name, "r")
    data = file.read
    file.close
    return data
  end
  
  puts "Start"
  puts read_file("/tmp/log/test.log")
  puts "End"
  </code></pre>
  
  <p>When I run this code, it only gives me this output:</p>
  
  <pre><code>Start
  
  End
  </code></pre>
  
  <p>I would expect the output to be something like this:</p>
  
  <pre><code>Start
  Start (from the reading of the test.log since it should have the word start already)
  End
  </code></pre>