0

I'm trying to watch a file in Windows Perl. I'm using Win32::ChangeNotify

Here is my code:

use strict;
use warnings;


require Win32::ChangeNotify;
use Data::Dumper;

my $Path="C:\\Eamorr\\";
my $WatchSubTree=0;
my $Events="FILE_NAME";

my $notify=Win32::ChangeNotify->new($Path,$WatchSubTree,$Events);
while(1){
    $notify->reset;
    $notify->wait;
    print "File changed\n";
}

But "File changed" never gets printed! I realise this is quite basic stuff, but I'm really struggling on this Windows platform.

I have a file in "C:\Eamorr\Eamorr.out" which I want to monitor for changes (a new line of data is appended to this file every ten minutes by another program).

When Eamorr.out is updated, I want to be able to run some Perl and populate a MySQL table.

Please help me watching the file Eamorr.out and printing the last line to the console.

p.s. I'm on Windows Server 2003

Many thanks in advance,

Eamorr
  • 9,872
  • 34
  • 125
  • 209
  • I've just installed Cygwin. I now have `tail -f Eamorr.out`... Seems to do the trick. – Eamorr May 29 '12 at 12:19
  • 3
    You should answer your own question and accept that if you found a solution so everybody knows the problem is resolved. – mpe May 29 '12 at 13:05

1 Answers1

3

This works on my Windows 7, Activestate Perl 5.16.

use feature ":5.16";
use warnings FATAL => qw(all);
use strict;
use Data::Dump qw(dump);
use Win32::ChangeNotify;

my $Path='C:\Phil\z\Perl\changeNotify\\';
my $WatchSubTree = 0;
my $Events = "SIZE";

say STDERR "Exists=", -e $Path;

my $notify=Win32::ChangeNotify->new($Path,$WatchSubTree,$Events) or say("Error=", Win32::GetLastError());
while(1)
 {$notify->reset;
  $notify->wait;
  say STDERR "File changed";
 }