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"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With