I installed File::ChangeNotify on Windows System and try to run the following code :
my $watcher =
File::ChangeNotify->instantiate_watcher
( directories => [ 'C:\files' ],
filter => qr/\.txt$/
);
# # blocking
while ( my @events = $watcher->wait_for_events() ) { print "new event"}
When I ran the script and try to create a new .txt
file or modify a .txt
file under c:\\files
the script didn't print anything.
It works for me (on linux) if I add this line:
$| = 1;
Then I see new event
.
Refer to perldoc perlvar : $|
or $OUTPUT_AUTOFLUSH
Here is the complete code:
use warnings;
use strict;
use File::ChangeNotify;
$| = 1;
my $watcher =
File::ChangeNotify->instantiate_watcher
( directories => [ 'C:\files' ],
filter => qr/\.txt$/
);
# # blocking
while ( my @events = $watcher->wait_for_events() ) { print "new event"}
UPDATE: As cjm astutely points out, adding a newline works as an alternative to $|
:
while ( my @events = $watcher->wait_for_events() ) { print "new event\n"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.