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.


In reply to Open3 and IO:Select on Win32 by Elegant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.