Skip Menu |

This queue is for tickets about the IO-Async CPAN distribution.

Report information
The Basics
Id: 127817
Status: open
Priority: 0/
Queue: IO-Async

People
Owner: Nobody in particular
Requestors: DBOOK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: IO::Async::Process - loss of buffered STDOUT/STDERR when previously redirected
When using IO::Async::Process with a code program, after STDOUT or STDERR has been redirected to /dev/null, it seems the on_read callback configured for stdout or stderr does not get called unless STDOUT or STDERR is subsequently autoflushed or enough data is sent, even when the stream closes. Test program: https://perl.bot/raw/qo5xhx If any of (1) the program is a command rather than code, (2) STDOUT/STDERR is not previously redirected to /dev/null, or (3) STDOUT/STDERR is autoflushed in the child code, then the program works and receives the data from the child process.
On Tue Nov 27 12:51:46 2018, DBOOK wrote: Show quoted text
Attached for posterity -- Paul Evans
Subject: rt127817.pl
#!/usr/bin/env perl use strict; use warnings; use IO::Async::Loop; use Future; # works if this is commented out open STDOUT, '>', '/dev/null' or die "Could not redirect STDOUT: $!"; my $loop = IO::Async::Loop->new; my $f = $loop->new_future; my @output; $loop->open_process( # or if you use command => 'echo passed values' instead # or if you set *STDOUT->autoflush(1) in the sub code => sub { print "passed values\n"; return 0 }, stdout => { on_read => sub { my ($stream, $buff, $eof) = @_; push @output, "$1" while $$buff =~ s/(.*\n)//; push @output, "$1" if $eof and $$buff =~ s/(.+)//; return 0; }, }, on_finish => sub { $f->done($_[1] >> 8) }, ); my $exit = $f->get; print STDERR "Exited $exit\nSTDOUT:\n", @output;