没有外壳,没有临时文件,也没有核心之外的任何东西。
use strict;
use warnings;
use IPC::Open3 qw( open3 );
my @pids;
{
my @cmd1 = ( 'perl', '-E', q{say for qw( ABC DEF );} );
my @cmd2 = ( 'perl', '-pe', q{$_=lc; warn(qq{x\n});} );
my @cmd3 = ( 'perl', '-pe', q{$_=ucfirst; warn(qq{y\n});} );
my $nul = $^O eq 'MSWin32' ? 'nul' : '/dev/null';
open(local *CHILD_STDIN, '<', $nul ) or die $!;
open(local *CHILD_STDOUT, '>', 'outfile' ) or die $!;
open(local *CHILD_STDERR, '>', 'error.log') or die $!;
push @pids, open3('<&CHILD_STDIN', local *PIPE1, '>&CHILD_STDERR', @cmd1);
push @pids, open3('<&PIPE1', local *PIPE2, '>&CHILD_STDERR', @cmd2);
push @pids, open3('<&PIPE2', '>&CHILD_STDOUT', '>&CHILD_STDERR', @cmd3);
*CHILD_STDIN if 0; # Silence warning. Already closed by open3.
*PIPE1 if 0; # Silence warning. Already closed by open3.
*PIPE2 if 0; # Silence warning. Already closed by open3.
close(CHILD_STDOUT);
close(CHILD_STDERR);
}
waitpid($_, 0) for @pids;