#!/usr/bin/perl -w $SIG{ALRM} = sub { command() }; command(); if ($@) { if ($@ =~ /timeout/) { command(); } else { alarm(0); # clear the still-pending alarm die; # propagate unexpected exception } } sub command { my $date = `date`; chomp($date); alarm(5); print "\n"; print "prompt $date > "; <>; alarm(0); }
In reply to Timeout on STDIN by yoda54
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |