Here, $buf might have some data in it that has not yet been printed, but
we were discarding it (and trying to read more) without printing it.
(In Perl, "do" ensures that the inner block runs at least once; without
"do" the condition is evaluated first.)
for (;;) {
if (waitpid ($pid, WNOHANG) != 0) {
# Subprocess died. Pass through any remaining data.
- print $buf while sysread ($in, $buf, 4096) > 0;
+ do { print $buf } while sysread ($in, $buf, 4096) > 0;
last;
}