First, it doesn't start at 63 and count up, it starts at 63 and counts down. I should have used 63 and 62, not 63 and 64. The reason given by the source is

Move FD to a number close to the maximum number of file descriptors allowed in the shell process, to avoid the user stepping on it with redirection and causing us extra work.

There's no mention of anything being special about fd 63 compared to fd 3 (or whatever) other than the user might be using fd 3 already. Perhaps then it's just the close-on-exec flag that varies.

use strict; use warnings; use Fcntl qw( F_GETFD F_SETFD FD_CLOEXEC ); use POSIX qw( dup2 ); sub keep_open_on_exec { my ($fh) = @_; my $flags = fcntl($fh, F_GETFD, 0); next if $flags & FD_CLOEXEC == 0; fcntl($fh, F_SETFD, $flags & ~FD_CLOEXEC); } open(my $src1_fh, '-|', echo => 'apples') or die("open: $!"); open(my $src2_fh, '-|', echo => 'oranges') or die("open: $!"); keep_open_on_exec($_) for $src1_fh, $src2_fh; system(diff => '/dev/fd/'.fileno($src1_fh), '/dev/fd/'.fileno($src2_fh +)) >= 0 or die("system: $!"); printf("\$?=%04X\n", $?);

Bingo!

1c1 < apples --- > oranges $?=0100

One other note, apparently some systems use /proc/dev/fd instead of /dev/fd.


In reply to Re^3: redirect output from a command to another command by ikegami
in thread redirect output from a command to another command by Allasso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.