in reply to Re: open (to read) and kill a pipe to a pipe
in thread open (to read) and kill a pipe to a pipe

Thanks! This looks promesing... but I can't figure it out.

I tried open2 (since I don't need the stderr from open3), but I don't even get the output of mycommand to show up...
what should I put in the while(< ??? >)... or did I even use the open2 command properly?
use IPC::Open2; $file = $ARGV[0]; local *FRGZ; local *TOGZ; local *FRCMD; $pid1 = open2(*FRGZ, *TOGZ, "gzip -dc $file"); $pid2 = open2(*FRCMD, '<FRGZ', 'mycommand'); while (<*FRCMD>) { print; }
maybe someone can provide an example of how to make this work...
My idea here is for the command "gzip -dc $file" to pipe its output to *FRGZ. Then I would pipe *FRGZ into "mycommand" and the output would be on *FRCMD .... ???

Replies are listed 'Best First'.
Re^3: open (to read) and kill a pipe to a pipe
by ikegami (Patriarch) on Aug 26, 2010 at 22:22 UTC

    open2 mixes STDERR into STDOUT, its arguments are "backwards", and it just ends up calling open3 anyway. I avoid it.

    use strict; use warnings; use IPC::Open3 qw( open3 ); my $file = $ARGV[0]; open(local *TO_CHAIN, '<', $file) or die("Can't open \"$file\": $!\n"); my $gz_pid = open3('<TO_CHAIN, local *PIPE, '>STDERR', 'gzip -dc'); my $mc_pid = open3('<PIPE', local *FR_CHAIN, '>STDERR', 'mycommand'); while (<FR_CHAIN>) { print; }