这就是解决我问题的方法
use strict;
use warnings;
use File::Monitor;
use File::Basename;
use Time::HiRes qw {usleep};
my $script = '/homw/goudarsh/Desktop/script.pl';
sub textfile_notifier {
my ($watch_name, $event, $change) = @_;
my @new_file_paths = $change->files_created; #The change object has a property called files_created,
#which contains the names of any new files
for my $path (@new_file_paths) {
my ($base, $fname, $ext) = fileparse($path, '.log'); # $ext is "" if the '.txt' extension is
# not found, otherwise it's '.txt'.
if ($ext eq '.log') {
print "$path was created\n";
system("perl $script $path \&");
}
}}
my $monitor = File::Monitor->new();
$monitor->watch( {
name => '/home/goudarsh/Desktop/logs/',
recurse => 1,
callback => {files_created => \&textfile_notifier}, #event => handler 1
} );
$monitor->scan;
while (1) {
$monitor->scan; #Scanning the directory one
sleep(2);
#usleep(10_000); #$microseconds = 750_000;
}
我只想执行
$script
具有
$path
作为一个论点,我使用forking创建子进程,但我对使用fork的概念是错误的,这是不需要的!现在不用分叉,我可以做任何需要的事情,我很高兴能学到新东西