Is definitely wrong: it'll fork the process and then both processes will proceed and will try to do the same thing.open( STDOUT, "|-" ) or die ("Can't open standard output: $!\n");
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:
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.my $output = `program -text -brief clone_error <<EOF $form r clone_from=$clone_from r EOF`;
In reply to Re: Reading programs output into a Scalar - How?
by Joost
in thread Reading programs output into a Scalar - How?
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |