Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaves STDERR in line buffered mode #63

Open
grr opened this issue Jan 28, 2024 · 1 comment
Open

Leaves STDERR in line buffered mode #63

grr opened this issue Jan 28, 2024 · 1 comment

Comments

@grr
Copy link

grr commented Jan 28, 2024

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;
@grr
Copy link
Author

grr commented Jan 29, 2024

using binmode(STDERR, ':unix'); is probably better here than $|=1, because although STDERR is initially unbuffered, $| is unset.

@grr grr changed the title Leaves STDERR in block buffered mode Leaves STDERR in line buffered mode Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant