in reply to Kill a command launched within script

The only thing that comes to mind (but probably isn't really the best solution) is to open the executable as a pipe, then close it after the eval block.
local $SIG {ALRM} = sub {die "alarm"}; my $fh; eval { alarm (2); open $fh, "-|", "$vmdiscover ..." or die "Couldn't open $vmdiscove +r: $!"; while (<$fh>) {}; alarm (0); }; if ($@ && $@ =~ /^alarm/) { print "Command has timed out"; } elsif ($@) { print "$@\n"; } close $fh;

Replies are listed 'Best First'.
Re^2: Kill a command launched within script
by massa (Hermit) on Nov 21, 2008 at 18:17 UTC
    In words, not in perl: you fork with open(my $chld, '-|'), in the child you send your PID to the father, and then exec the $vmdiscover thing; in the parent, you read the PID of the child, and after the timeout you just kill it.
    []s, HTH, Massa (κς,πμ,πλ)