Your first link is a piped-open command, not a pure pipe, and it dosn't use threads at all. A piped open locks the filehandle to a command, whearas a pure pipe is more flexible.

Your second link has nothing to do with conventional pipes at all, it states

Instead of passing a handle to the object back to the parent so that it can control it, try giving the parent a shared variable that indicates what it wants the child to do to the object.

Neither of these show how to setup conventional pipes to threads, let alone show how to read output from many threads/pipes in a simple select loop.

Sure, there are many ways to do communication between threads and parent, but neither of your examples show how to use IO::Select to monitor multiple threads whose output is directly fed to pipes, an even more precise, an IO::Pipe object.

Furthermore, I find your code overly complicated, for example you do

# save STDOUT open(my $STDOUT_ORIG, ">&", \*STDOUT) or die; # connect TO_CHILD_PROC with CHILD_PROC pipe(CHILD_PROC, TO_CHILD_PROC); # change STDOUT to TO_CHILD_PROC # --> STDOUT of child process is set to TO_CHILD_PROC and # this is connected via pipe with CHILD_PROC open(STDOUT, ">&", \*TO_CHILD_PROC);
Ugh!!!

When all that is needed is

# in thread my $wh = $pipe->writer; $wh->autoflush(1); print $wh "whatever \n" ;

Sorry, but you have not shown any link of yours that uses IO::Select and IO::Pipe in such a clearcut and simple manner, for monitoring multiple threads with 1 loop, as my script does. So I feel it is my right to defend it's virtue and put in Cool Uses for Perl, so others can use the simple technique. Even googling for "perl threads pipe mkfifo" yields few real scripts, and NONE of them combine IO::Select with the simplicity of IO::Pipe.

So sorry BrowserUk, this time your blusterous hot air dosn't fill the balloon.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re^4: Using Select and pipes to communicate with threads by zentara
in thread Using Select and pipes to communicate with threads by zentara

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.