pronini has asked for the wisdom of the Perl Monks concerning the following question:
usage: perl timeout 'tcpdump -n -i em0' It works perfectly. Runs tcpdump command and kills the perl script and tcpdump after 5 seconds. The main problem is buffering. When i have not a lot of captured packets, script doesn't show them. Could u please help me with that? I tried to do#!/usr/bin/perl use strict; my $pid = 0; my $cmd = $ARGV[0]; eval { my $process; local $SIG{ALRM} = sub { kill 'INT', $pid; close $process; die "ti +meout\n" }; alarm( 5 ); $pid = open $process, "$cmd |"; while (<$process>) { chomp ($_); print $_, "\n"; } };
doesn't help.select $process; $|=1; select $process;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cmd timeout
by ww (Archbishop) on Apr 07, 2010 at 10:53 UTC | |
by rubasov (Friar) on Apr 07, 2010 at 11:11 UTC | |
by pronini (Initiate) on Apr 07, 2010 at 11:36 UTC | |
by ambrus (Abbot) on Apr 07, 2010 at 10:56 UTC | |
by bart (Canon) on Apr 07, 2010 at 11:18 UTC | |
by cdarke (Prior) on Apr 07, 2010 at 11:11 UTC | |
by ikegami (Patriarch) on Apr 07, 2010 at 15:08 UTC |