2012-05-29 59 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"; 
}