in reply to Time out
Yes there is, it's named alarm. I'm not exactly sure what you mean by a remote shell... are you using Expect, or Net::Telnet or system('sh') or something else entirely? Nevertheless, your code is going to look something like this:
eval { local $SIG{ALRM} = sub { die "too long\n" }; alarm 30; #seconds system( '/usr/local/bin/scp', 'me@example.com:foo.txt', '.' ); alarm 0; }; if ($@ eq "too long\n") { # time out } elsif ($@) { #something else went wrong } else { # ok }
Note that your remote command could involve a Win32 machine, however you cannot run this code on a Win32 machine as alarm is not implemented on that platform. Also not that you want your signal handler $SIG{ALRM} to be as simple as possible. The more it does, the more chance you run the risk of dumping core and other other unpleasant things
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Time out (or use Win32::Event)
by particle (Vicar) on Jun 18, 2002 at 15:34 UTC |