in reply to redirect output from a command to another command
use strict; use warnings; use POSIX qw( dup2 ); open(my $src1_fh, '-|', echo => 'apples') or die("open: $!"); open(my $src2_fh, '-|', echo => 'oranges') or die("open: $!"); dup2(fileno($src1_fh), 63) or die("dup2: $!"); dup2(fileno($src2_fh), 64) or die("dup2: $!"); system(diff => '/dev/fd/63', '/dev/fd/64') >= 0 or die("system: $!"); printf("\$?=%04X\n", $?);
1c1 < apples --- > oranges $?=0100
On systems without /dev/fd, it reportedly uses temporary files.
You could also use named pipes.
Update: What is 64 should be 62.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: redirect output from a command to another command
by Allasso (Monk) on Mar 02, 2011 at 01:39 UTC | |
by ikegami (Patriarch) on Mar 02, 2011 at 02:49 UTC | |
by Allasso (Monk) on Mar 02, 2011 at 15:58 UTC | |
by ikegami (Patriarch) on Mar 02, 2011 at 16:56 UTC | |
by Allasso (Monk) on Mar 02, 2011 at 16:21 UTC | |
by ikegami (Patriarch) on Mar 02, 2011 at 17:03 UTC |