mariadb/mysql-test/lib/My/Tee.pm
Sergei Golubchik e49c1d1cef mtr: force-flush stderr and stdout
prevents buffering in cases like

  ./mtr | tee log
2018-02-24 09:39:57 +01:00

25 lines
349 B
Perl

package My::Tee;
use IO::Handle;
# see PerlIO::via
our $copyfh;
sub PUSHED
{
open($copyfh, '>', "$::opt_vardir/log/stdout.log")
or die "open(>$::opt_vardir/log/stdout.log): $!"
unless $copyfh;
bless { }, shift;
}
sub WRITE
{
my ($obj, $buf, $fh) = @_;
print $fh $buf;
$fh->flush;
print $copyfh $buf;
return length($buf);
}
1;