我希望一旦印出来就得到孩子的输出,而不是在孩子结束的时候,
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来实现。