Aclhk Aclhk wrote:
> i want to kill spawned process and its child if image*.tiff exists or
> timeout.
> c:\\test\\a.pl is to generate the tiff by print the acrobat reader to
> default printer which creates the tif file.
>
> i have tried the following without success.
>
> use Win32::Job;
>
> my $job = Win32::Job->new;
>
> # Run for 10 seconds
> print "start ......";
> #$job->spawn($Config{perlpath}, "perl");
> $job->spawn($Config{perlpath}, "perl c:\\test\\a.pl");
> #$job->run(10);
>
>
> $ok = $job->watch( sub {
> return 1 if ((glob "image*.tiff") || sleep (30));
> }
> , 1);
>
> If image*.tiff is changed to an file already existed, the spawn process
> is terminated very quickly. It could not detect image*.tiff if it is
> generated by a.pl (by printer driver). it times out after 30 secs.
>
> I am a newbie to perl. pls kindly advise. if you know win32::process,
> pls advise code, too.
This seems to work (assuming the TIFF is generated in the current working
dir and the TIFF created is named something like 'image1.tiff':
use strict;
use warnings;
use Config;
use Win32::Job;
my $MAX_WAIT = 10; # seconds to wait for TIFF
my $job = Win32::Job->new;
$job->spawn($Config{perlpath}, 'perl a.pl');
my $start = time;
# assumes that a TIFF file is created in this (.) dir
print "watch for TIFF\n" if $debug;
$job->watch(
sub {
return 1 if glob ('image*.tiff');
my $diff = time - $start;
if ($diff > $MAX_WAIT) {
print "Timeout waiting for TIFF - exiting\n";
return 1;
}
return 0;
}, 1);
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs