I'm a bit too tired to figure out if what you're trying to do is even possible with a piped open to self, but this:
open( STDOUT, "|-" ) or die ("Can't open standard output: $!\n");
Is definitely wrong: it'll fork the process and then both processes will proceed and will try to do the same thing.

You'll want to split the task between the parent (who can write to the child) and the child (who can read from STDIN - NOT STDOUT!).

my $pid = open( CHILD, "|-" ); unless (defined $pid) { die ("Can't open standard output: $!\n"); } if ($pid) { # in parent process (will write to CHILD) } else ($pid) { # in child process (will read from STDIN) }

Also see perlipc.

update:

After some re-reading of your code, something like this will probably work too, and it's a LOT less complicated:

my $output = `program -text -brief clone_error <<EOF $form r clone_from=$clone_from r EOF`;
In other words, unless you really need to react to the programs output while it's running - i.e. you need to adjust the program's input based on it's output - you don't need to open a read/write pipe at all. Just supply all the input in one go and collect the output later.


In reply to Re: Reading programs output into a Scalar - How? by Joost
in thread Reading programs output into a Scalar - How? by awohld

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.