in reply to avoiding shell escapes with exec()
sub cmd_wrapper { my( $cmd ) = @_; my( $rc , $out ); eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 15; $out = (`$cmd`)[0]; # Get first line of output $rc = $?; alarm 0; }; if( $@ ) { die "Eval failed for $cmd but not because of alarm" if $@ ne " +alarm\n"; # Propogate unexpected errors die "Eval failed for $cmd because alarm timed out"; } die "Return code undefined for $cmd" unless defined $rc; return $rc, $out if wantarray; return $rc; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: avoiding shell escapes with exec()
by chunter (Initiate) on Jun 27, 2007 at 18:46 UTC | |
by Argel (Prior) on Jun 27, 2007 at 22:14 UTC |