파일을보기 위해 아래의 테스트 코드를 실행하면 파일에 'vim'을 입력하면 이벤트가 감지됩니다. 또는 쓰기 종료). 파일에 'echo'를하거나 perl을 통해 텍스트를 추가하는 것은 감지되지 않습니다.Perl Inotify가 append에 응답하지 않음 (즉, echo 'test'>> 파일)
test_inotify.pl :
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Carp;
use IO::File;
use Linux::Inotify2;
$|++;
my $readfile = shift;
#my $action = "IN_CLOSE_WAIT";
#my $action = "IN_MODIFY";
#my $action = "IN_OPEN";
my $action = "IN_ALL_EVENTS";
unless ($readfile) { $readfile = "test.txt" };
my $inotify = Linux::Inotify2->new();
$inotify->watch($readfile, $action)
or die "Inotify watch on " . $readfile . "failed: $!\n";
while() {
my @events = $inotify->read();
unless (@events > 0) {
print "Inotify Read Error: $!\n";
exit;
};
foreach my $event (@events) {
print "Detected Event: " . $event->fullname . "\n";
};
};
test_fh_write.pl : 나는 에코뿐만 아니라 test_fh_write.pl으로 시도했습니다
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use Carp;
use IO::File;
$|++;
my $readfile = shift;
unless ($readfile) { $readfile = "test.txt" };
my $readfh = IO::File->new($readfile, ">>") or
#my $readfh = IO::File->new($readfile, ">") or
die "Cannot open $readfile: $!";
$readfh->autoflush(1);
if ($readfh) {
print $readfh "test\n\n";
};
undef($readfh);
은 다음과 같이 명령 : '에코 >> TEST.TXT을 ','echo "test">> test.txt '등
"$ |" ($ fh-> autoflush (1)을 사용해도), 아무 소용이 없습니다. test_inotify.pl에 정의 된 $ action 변수 각각은 시도했지만 모두 똑같습니다.
감사합니다. 희망적으로 이것은 다른 사람을 돕는다. – xyon