sniperd has asked for the wisdom of the Perl Monks concerning the following question:
To keep it simple I just chucked in there ping -t for testing. The real code is calling phantomjs to hit a website and the .exe just blows up sometimes, basically getting stuck and I the script will just sit there. Is there some simple command I can use to call command line on windows and have it just die (or continue) if a certain number of seconds have passed? Thank you in advance.use warnings; use strict; main (); sub main { eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm 2; my $data = `ping 127.0.0.1 -t`; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors } else { print "got here\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: alarm in windows, alternative?
by BrowserUk (Patriarch) on Mar 06, 2015 at 16:16 UTC |