#!/usr/bin/env perl # # impatiently - abort a command if it doesn't start to produce any output # # $Id$ use warnings; use strict; # try me with # $0 -i sh -c 'i=0; while sleep 4; do i=`expr $i + 1`; echo $i; done' # $0 -i sh -c 'i=0; while sleep 5; do i=`expr $i + 1`; echo $i; done' # $0 -i sh -c 'i=0; while sleep 4; do i=`expr $i + 1`; echo $i>&2; done' # (first will continue, second and third will be killed) # BUG: doesn't always produce the PING header with ping on FreeBSD # I'll leave it for now, truss has no -f option there use strict; #$ENV{PATH} = '/bin:/usr/bin:/usr/ucb:' . $ENV{PATH}; # leftover from sh days? # it works as follows: we plan to kill the command as long as $t exists # # a subprocess is started that times out after $sex seconds, if $t # still exists, kills the other process, and removes $t # # then, the command is started; with -i, piping its output through a wrapper # that will remove $t upon receiving the first line of output # note: on a slow machine, the startup time may exceed one second #--- config ---# # my $sex = 5; # default interval to wait before interrupt #--- error handling ---# # sub puke { @_ && warn "fatal error: ", join( ' ', @_ ), "\n"; print STDERR < ) ) { !$waitforinput or alarm 0; print $firstline; } print while ;