I have the following situation that I don’t have a good solution:
One process periodically will append its output to a file (which is
not under my control), I want to write a ruby problem to detect and
report only the new stuff that went into the output file … Besides
the brute force way such as opening the file and counting the lines
etc, is there a better solution to it?
One process periodically will append its output to a file (which is
not under my control), I want to write a ruby problem to detect and
report only the new stuff that went into the output file … Besides
the brute force way such as opening the file and counting the lines
etc, is there a better solution to it?
You can use File.stat(‘filename’).size to get the number of bytes in
the file or .mtime to find the last modification time. If the bytes
and/or time changes you can then open the file and grab the new lines.
You can use File.stat(‘filename’).size to get the number of bytes in
the file or .mtime to find the last modification time. If the bytes
and/or time changes you can then open the file and grab the new lines.
Gary W.
You’re welcome! That approach has worked for me many times in the
past in many languages, including Ruby. Give it a run!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.