2012-05-29 58 views
0

我想在Windows Perl中观看文件。我使用Win32 :: ChangeNotifyPerl Windows - 观看文件并阅读最后一行

这里是我的代码:

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"; 
} 

但是 “文件更改” 永远不会被显示出来!我意识到这是非常基本的东西,但我真的在这个Windows平台上苦苦挣扎。

我在“C:\ Eamorr \ Eamorr.out”中有一个文件,我想要监视其中是否有更改(每十分钟一个新的数据行被另一个程序附加到该文件中)。

当Eamorr.out更新时,我希望能够运行一些Perl并填充MySQL表。

请帮我看看文件Eamorr.out并将最后一行打印到控制台。

p.s.我在Windows Server 2003

提前许多感谢,

+0

我刚安装了Cygwin。我现在有'tail -f Eamorr.out' ......似乎能做到这一点。 – Eamorr

+3

您应该回答自己的问题,并接受如果您找到解决方案,以便大家都知道问题已解决。 – mpe

回答

3

这工作在我的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"; 
}