21. ps al ¦ cat -n
STDOUT
or
STDERR
STDIN
結果を渡す
※あくまでイメージです
STDIN
or
Not
STDOUT
or
STDERR
➀
➁ ➂
➃
22. #!/usr/bin/env perl
use strict;
use warnings;
my @cmd1 = ("ps", "al");
my @cmd2 = ("cat", "-n");
pipe READ1, WRITE1;
pipe READ2, WRITE2;
if (fork) {
close READ1;
close WRITE2;
wait;
open STDIN, ">&", READ2;
exec @cmd2;
} else {
close READ2;
close WRITE1;
open STDOUT, ">&", WRITE2;
exec @cmd1;
}
例
pipe.pl