Thanks for your reply. I found some sample code on the web that uses IPC::Open3 and used it in my program. Is it requirs to write data to the WRITE descriptor before I can read from it? My binary writes data to STDOUT/STDERR first, and then reads STDIN.
sub ExecCmd { my $cmd = shift; my $pid = open3(\*WRITE,\*READ,\*ERROR,$cmd); unless (defined $pid) { LogError("Failed to execute $cmd"); return undef; } LogInfo("PID is $pid"); my $select = new IO::Select(); $select->add(\*READ); $select->add(\*ERROR); foreach my $handle ($select->can_read) { LogInfo("handle is $handle"); my $buf = ""; if($handle eq \*ERROR) { sysread(ERROR,$buf,BUFFER); close ERROR; if($buf) { LogInfo("ERROR -> $buf"); } } else { sysread(READ,$buf,BUFFER); close READ; if($buf) { LogInfo("READ -> $buf"); } } } print WRITE "0\n";
In the above, the program seems to be waiting for some kind of input after it prints the PID - never enters the foreach loop. How can I solve the above problem?

Thanks!


In reply to Re^2: Executing command from perl script with input/output by linuxfan
in thread Executing command from perl script with input/output by linuxfan

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.