perltcpreplay

Why does this script that uses tcpreplay not wait for user input?


The following snippet will only wait for the user to hit Enter the first time; after that, it cycles through all the rest of the .pcap files without waiting for user input.

$| = 1;

while (<*.pcap>) {
    print "$_";
    <STDIN>;

    system("tcpreplay -i eth0 -M 20 $_");
}

Why doesn't this wait for user input on every loop iteration?


Solution

  • Do you care about tcpreplay output? Redirecting stdout and stderr seems to fix this problem:

    system("tcpreplay -i eth0 -M 20 $_ >/dev/null 2>&1");
    

    Alternatively, you can use this to capture tcpreplay output:

    my $tcpreplay_output = `tcpreplay -i eth0 -M 20 $_ 2>&1`;