It's because of STDOUT buffering in the video
program. print
is line-buffered only if it goes to an interactive terminal. Otherwise it uses a much bigger buffer, and the accumulated output is emitted in one big chunk when video
exits. Try flushing after each print or use autoflush.
$| = 1; # Enables autoflush
By the way I don't get why you open a pipe TO video
, it does not read anything. It should be
system "./video";
If you have a program that you can't modify but does not autoflush, you are in trouble. Except, you're not. You can use a pseudoterminal instead of a pipe. I've never done it. But chapter 64 of the book "The UXIX Programming Interface" is about pseudoterminals.