Nevermind, I see it isn't.
I have a script that uses system() to execute a command line which
compacts an Access database. This command never returns anything other
than 0, on success or failure. Generally though, if the task fails it
will just hang (return nothing). What I would like to do is create some
kind of alarm process which will wait so long for that 0 return value,
and if it doesn't get it in that time, just continue with the rest of
the script. If anyone can tell me of a way I might do that or a module
that will help me, I'd appreciate it.
thanks in advance
spark
use strict;
use warnings;
print " perl version is $]\n";
$SIG{ALRM} = sub { die "timeout" };
eval {
alarm(3);
sleep (6);
alarm(0);
};
if ($@) {
if ($@ =~ /timeout/) {
print "Yep!! it timed out\n"; # timed out; do
what you will here
} else {
alarm(0); # clear the still-pending alarm
die; # propagate unexpected exception
}
}
output isF:\scripts>time.pl
perl version is 5.008
Yep!! it timed out
F:\scripts>
Hope this helps
Mothra
Oh - I went to activestate and looked up the perlport page there. I
assumed it was for 5.8. If it's working for you, I'll try 5.8 (I'm on
5.6). Thanks!
spark
Seems to be impemented to some degree, at least.
With 5.8:
perl -e "alarm(2);for(;;){}"
That will produce (after a couple of seconds) the message:
Terminating on signal SIGALRM(14)
Then exits immediately.
With 5.6.1
perl -e "alarm(2);for(;;){}"
That will exit immediately with the message:
The Unsupported function alarm function is unimplemented at -e line 1.
Just how far the support extends, I don't know :-)
Cheers,
Rob
"spark" <sp...@dcwis.nodurnspam.com> schrieb im Newsbeitrag
news:MPG.18a1bbf08...@news-central.giganews.com...
> Is alarm() implemented for Win32 in the latest version of Perl?
perl -MConfig -le 'print $Config{d_alarm}'
(use "" on Win32) shows, wether alarm() is available.
HTH,
Peter Dintelmann