in reply to Threads or no Threads
Here's a rather simple solution that may work for you.
#! perl -slw use strict; our $WAIT ||= 10; my $cmd = 'perl -e"$|++;sleep 1, print for 1 .. 10" |'; my $pid = open my $cmdFh, $cmd or die "Couldn't run '$cmd': $!"; sleep 1 while kill 0, $pid and $WAIT--; kill 3, $pid and warn 'Command timed out' if $WAIT; my $results = do{ local $/; <$cmdFh> }; print "Got: '$results'";
A few simple tests
c:\test>junk9 -WAIT=2 Command timed out at c:\test\junk9.pl line 11. Got: '12' c:\test>junk9 -WAIT=9 Command timed out at c:\test\junk9.pl line 11. Got: '12345678' c:\test>junk9 -WAIT=10 Got: '12345678910' c:\test>junk9 -WAIT=11 Got: '12345678910'
|
---|