All,

I'm trying to write a script that will execute a process in the background, monitoring STDOUT and STDERR to obtain data, then print "QUIT" on STDIN to kill off the application. I'm developing on XP but this will run on *nix.

I'm attempting to use open3 and IO::Select to read both STDOUT and STDERR without blocking. It ain't working...

  • if I dumpValue the select handle I never see STDERR get set.
  • I never got into the while because "$sel->can_read" appears to never return a ready handle
  • I'm open to other approaches here.

    my ($read, $write, $error); my $pid = open3( $write, $read, $error, "$em_command &") || die ERROR. +" : Unable to execute "; write_log (DEBUG, "Maintenance Proxy pid = $pid"); # exception occured if ($pid =~ /^open3:/) { write_log (ERROR, $pid); exit 1; } my $sel = IO::Select->new(); $sel->add($read); dumpValue ($sel); print "---\n"; $sel->add($error); dumpValue ($sel); print "---\n"; my ($rh, $inStr); while(my @ready = $sel->can_read) { foreach my $handle (@ready) { if ($handle == $error) { my $numBytesRead = sysread($rh, $inStr, 1024); print "ERROR: $inStr"; } else { my $numBytesRead = sysread($rh, $inStr, 1024); print "INFO: $inStr"; } $sel->remove($handle) if eof($handle); } }

    In reply to open3 and IO::Select by stephens2k

    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.