After using capture(), STDERR is left in line buffered mode, i.e. it is no longer "hot". You have to manually set $| to restore unbuffered mode.
Example program demonstrating the issue:
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use Capture::Tiny qw(capture);
print STDERR __LINE__; # prints immediately as expected
# my $out = `date`; # stderr is fine if using this line instead of the next
my ($out, $err) = capture { system 'date' }; # leaves stderr in buffered mode
say $out;
# $| = 1, select $_ for select STDERR;
# won't print unless prev line is uncommented or script exits normally.
print STDERR __LINE__;
sleep 10;
After using
capture()
, STDERR is left in line buffered mode, i.e. it is no longer "hot". You have to manually set$|
to restore unbuffered mode.Example program demonstrating the issue: