Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
References to actual command files and directory structures have been changed in accordance with security protocol.#!/usr/bin/perl -w use strict; use FileHandle; my $command="/usr/local/files/command"; my @array; my $timeout=50; eval{ local $SIG{ALRM}=sub{die "alarm\n"}; alarm $timeout; my $pid = open my $sys, "-|", $command or die $!; @array=<$sys>; close $sys; alarm 0; }; if($@){ die unless $@ eq "alarm\n"; }else{} if($@ eq "alarm\n"){print "COMMAND FAILURE!\n";} my $rule=qr/string/; for(my $i=0; $i<@array; $i++){ my $line=$array[$i]; $line =~ s/\s+//g; if($line =~ m/$rule/){ my $VAR=(split $rule, $line)[1]; print "VALUE VAR: $VAR\n"; exit; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: command timeout not working
by eserte (Deacon) on May 14, 2004 at 13:37 UTC | |
|
Re: command timeout not working
by Crackers2 (Parson) on May 14, 2004 at 15:30 UTC | |
|
Re: command timeout not working
by dave_the_m (Monsignor) on May 14, 2004 at 14:18 UTC | |
by Anonymous Monk on May 14, 2004 at 14:31 UTC | |
by dave_the_m (Monsignor) on May 14, 2004 at 14:44 UTC | |
|
Re: command timeout not working
by bluto (Curate) on May 14, 2004 at 15:27 UTC | |
|
Re: command timeout not working
by Anonymous Monk on May 14, 2004 at 13:51 UTC |