On May 11, 12:56 am, [email protected] (Weizhong Dai) wrote:
> Hi all,
>
> ---------------------------------
> $pid = open(README, "program arguments |") or die "Couldn't fork: $!\n";
> while (<README>) {
> # ...}
>
> close(README)
> ----------------------------------
>
> my problem is: I read from README, but if waiting for next input is
> timeout, end reading. Is there any timer or method I could use for
> this purpose?
>
> thanks.
perldoc -q timeout
perldoc perlipc
Here's an example with a 5 second timeout:
$pid = open(my $readme, "program arguments |")
or die "Couldn't fork: $!\n";
my $timeout = 5;
eval {
local $SIG{ALRM} = sub { die "timeout"; };
alarm( $timeout );
print while <$readme>;
alarm(0);
1;
} or die "eval error: $@ ";
...
--
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/