#!perl -w use strict; use Win32::ChangeNotify; use Getopt::Long; GetOptions( 'dir|d:s' => \my @directories, ); my $child; sub launch_child { warn "Launching [@_]"; my $pid = system(1, @_); warn "Server PID: $pid"; $pid; }; my $path = $directories[0]; while (1) { my $child = launch_child(@ARGV); my $notify = Win32::ChangeNotify->new($path,1,'DIR_NAME FILE_NAME LAST_WRITE SIZE'); $notify->wait or warn "Something failed: $!\n"; # There has been a change. warn "Killing $child"; kill 9 => $child; undef $child; }; END { kill $child if $child; }; __END__ =head1 SYNOPSIS server-restarter.pl -d lib -- perl -w \strawberry\perl\bin\plackup --server Twiggy bin\server.psgi =head1 USAGE server-restarter.pl -d DIRECTORY -- [command to launch] =over 4 =item * C<-d> - the directory tree to watch for changes =back =cut