Elegant has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm currently trying to port a project over from linux to Windows and hit a bit of a snag when using Open3 and IO::Select to read both STDOUT and STDERR.
It appears that if I dump the select handle I never see STDERR get set and I never got into my loop because can_read is never ready. I'm not quite sure of how to work around this on Windows and could really use some help!
sub sys { my $self = shift; my $app = shift; my ($pid, $in, $out, $err, $sel, $buf); $err = gensym(); more(); TRACE "sys > $app @_"; $pid = open3($in, $out, $err, $app, @_) or LOGDIE "failed to open $app +: @_"; $sel = new IO::Select; $sel->add($out, $err); SYSLOOP: while(my @ready = $sel->can_read) { foreach my $fh (@ready) { my $line = <$fh>; if(not defined $line) { $sel->remove($fh); next; } if($fh == $out) { TRACE "sys < $line"; $buf .= $line; } elsif($fh == $err) { TRACE "sys !! $line"; $buf .= $line; } else { ERROR "Shouldn't be here\n"; return undef; } } } waitpid($pid, 0); less(); return $buf; }
Using strawberry perl 5.18.1.1 64bit on Windows 7 x64.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Open3 and IO:Select on Win32
by BrowserUk (Patriarch) on Sep 12, 2014 at 05:29 UTC | |
by Elegant (Novice) on Sep 12, 2014 at 07:00 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2014 at 08:23 UTC | |
by Elegant (Novice) on Sep 12, 2014 at 17:40 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2014 at 19:49 UTC | |
|
Re: Open3 and IO:Select on Win32
by zentara (Cardinal) on Sep 12, 2014 at 11:23 UTC |