It would appear that the output from hping
is fully buffered when piped to perl
for further line-by-line processing, so piping hping to perl doesn't work.
hping --icmp-ts example.ca | perl -ne 'if (/Originate=(\d+) Receive=(\d+) Transmit=(\d+)/) { ($o, $r, $t) = ($1, $2, $3); } if (/tsrtt=(\d+)/) { print $r - $o, " ", $o + $1 - $t, "\n"; }'
How do I change hping from being fully buffered to being line buffered when piped?
Not a duplicate of the following question, since no solution works in OpenBSD base:
unbuffer
andstdbuf
aren't available in BSD? – slm Nov 24 '13 at 12:23stdbuf
isn't in OpenBSD.unbuffer
is, but it isn't immediately obvious: you need to install theexpect
port. – Gilles 'SO- stop being evil' Nov 24 '13 at 21:40unbuffer
, replacingif
with$|++;if
makes no difference; I would imagine that it's because you can't change the buffering after the fact – cnst Oct 03 '17 at 06:28