in reply to open (to read) and kill a pipe to a pipe

I'm not even sure what signal I should be sending with the kill

Windows has two signals, Ctrl-C and Ctrl-Break. It uses message passing primarily, but that's for application with Windows. It can terminate processes forcibly.

I think you can send the Ctrl-C and Ctrl-Break signals using kill, but I don't know which numbers do this.

kill 9 surely results in the the system call to terminate a process. That's drastic.

BUT it does not kill the gzip or mycommand processes when it gets to the "kill 9, $pid".

It kills the shell whose pid is in $pid. This doesn't kill the shell's children. I don't know one would achieve that.

One solution would be to eliminate the shell and do the piping yourself.

Replies are listed 'Best First'.
Re^2: open (to read) and kill a pipe to a pipe
by darist (Initiate) on Aug 26, 2010 at 21:59 UTC
    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 .... ???

      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; }