我想在打印后立即获得输出,而不是在孩子完成后立即输出,即
use strict;
use warnings;
# this is only example of buffered child output
open (my $fh, "-|", "perl", "-E", "sleep(1),say for 1..10") // die $!;
# all lines are buffered
while (my $line = <$fh>) {
print $line;
}
在Linux上,可以使用unbuffer来实现。