in reply to Autoflush fails

autoflush means flush after write (print), but you do not print to TCPDump

Replies are listed 'Best First'.
Re^2: Autoflush fails
by sophate (Beadle) on May 31, 2012 at 03:50 UTC

    Thanks for your reply. What I want is to flush the results of "sudo /usr/sbin/tcpdump -i $Interface host $Multicast 2>/dev/null |" to TCPDump. I tried "$| = 1" but it didn't work either. Any suggestion I can make the while loop to print the traffic at once? I tried the sudo command in a bash shell and I can see the results right away. However, the output of the sudo tcpdump feeding to TCPDump is batched in my Perl program. This causes the rest of the codes(removed here) to fail.

      Autoflush is something you do in your program, to control the output of your program , not something you can do to other programs

      Other than changing your invocation (sudo ... ) there is nothing you can do

      You say sudo ... works from bash, but does  sudo ... |perl -pe 1 work the same?

        Really appreciate your help :-)

        The results of "sudo tcpdump" are redirected to STDOUT right away.

        ,"sudo /usr/sbin/tcpdump -i eth3 host 226.1.109.109 2> +/dev/null"

        However, the results are buffered if I pipe it to "perl -pe 1"

        ,"sudo /usr/sbin/tcpdump -i eth3 host 226.1.109.109 2> +/dev/null | perl -pe 1"

        Any alternative to a file handle to get the sudo resluts from a pipe?