in reply to Re^2: avoiding shell escapes with exec()
in thread avoiding shell escapes with exec()
...the only issue is that @pids doesn't seem to be globally referenced...I'm not sure what you mean by that. This seems to work:
Sorry if I'm misunderstanding, but glad you got it working.my ($fh, @pids) = pipeline( [qw(ls -1)], [qw(sed -e s/t/a/g)], [qw(sed -e s/z/b/g)], # Let's "hang" for 20 seconds [qw(sleep 20)], ); eval { local $SIG{ALRM} = sub { die "alarm\n" }; # Assume we're "hung" after 5 seconds alarm 5; while (<$fh>) { print "$.:$_"; } }; if ($@) { die unless $@ eq "alarm\n"; # Kill the sleep process kill 1, $pids[0]; # timed out } else { close $fh; } print "Pids: @pids\n";
|
|---|