<p>I would like to monitor a log file that is being written to by an application. I want to process the file line by line as, or shortly after, it is written. I have not found a way of detecting that a file has been extended after reaching eof.</p>

<p>The code needs to work on Mac and PC, and can be in any language, though I am most familiar with C++ and Perl.</p>

<p>Does anybody have a suggestion for the best way to do it?</p>

[{'answer_id': 62843, 'author': 'David Precious', 'author_id': 4040, 'author_profile': 'https://Stackoverflow.com/users/4040', 'pm_score': 4, 'selected': True, 'text': '<p>In Perl, the <a href="http://search.cpan.org/dist/File-Tail/" rel="noreferrer">File::Tail</a> module does exactly what you need.</p>\n'}, {'answer_id': 62875, 'author': 'tzot', 'author_id': 6899, 'author_profile': 'https://Stackoverflow.com/users/6899', 'pm_score': 2, 'selected': False, 'text': '<p>A generic enough answer:</p>\n\n<p>Most languages, on EOF, return that no data were read. You can re-try reading after an interval, and if the file has grown since, this time the operating system will return data.</p>\n'}, {'answer_id': 62880, 'author': 'Stu Thompson', 'author_id': 2961, 'author_profile': 'https://Stackoverflow.com/users/2961', 'pm_score': 2, 'selected': False, 'text': '<p>You should be able to use read the standard io from tail -f</p>\n'}, {'answer_id': 63446, 'author': 'Bruno De Fraine', 'author_id': 6918, 'author_profile': 'https://Stackoverflow.com/users/6918', 'pm_score': 2, 'selected': False, 'text': '<p>The essense of <code>tail -f</code> is the following loop:</p>\n\n<pre><code>open IN, $file;\nwhile(1) {\n  my $line = &lt;IN&gt;;\n  if($line) {\n    #process line...\n  } else {\n    sleep(1);\n    seek(IN,0,1);\n  }\n}\nclose IN;\n</code></pre>\n\n<p>The <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlfunc.pod#seek" rel="nofollow noreferrer">seek</a> call is to clear the EOF flag.</p>\n'}, {'answer_id': 63997, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d have thought outputting the actions via tee, and thence tail\'ing (or using the loop <a href="https://stackoverflow.com/questions/62832#63446">above</a>) the file created by tee some use.</p>\n'}]
['https://Stackoverflow.com/questions/62832', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/259/']