Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!mips!sgi!shinobu!odin!sgihub!dragon!bananaPC.wpd.sgi.com!ciemo From: ciemo@bananaPC.wpd.sgi.com (Dave Ciemiewicz) Newsgroups: comp.sys.sgi Subject: Re: Pipe input file redirection. Message-ID: <1990Sep27.010822.29149@relay.wpd.sgi.com> Date: 27 Sep 90 01:08:22 GMT References: <9009262123.AA24525@mcirps2.med.nyu.edu> Sender: news@relay.wpd.sgi.com ( CNews Account ) Reply-To: ciemo@bananaPC.wpd.sgi.com (Dave Ciemiewicz) Organization: Silicon Graphics, Inc. Lines: 51 In article <9009262123.AA24525@mcirps2.med.nyu.edu>, karron@MCIRPS2.MED.NYU.EDU writes: > > How do I pipe the stdout and stderr files from a collection of programs > into the stdin of another program ? > > This does not work. > > #! /bin/sh > ( > BMDstat $1 2>1 > od -d $1 2048. d > ) | more > > I am still, after all these years, mystified by sh and file numbers. > > Is there a similar incantation for pipes ? > > dan. The UNIX convention for Standard I/O (stdio) is to assign input and output streams accordingly: Stream File Descriptor Number ====== ====================== stdin 0 stdout 1 stderr 2 If you look in /usr/include/stdio.h, you see the following: #define stdin (&_iob[0]) #define stdout (&_iob[1]) #define stderr (&_iob[2]) The first 3 file descriptors are allocated to stdio. Nothing magical, just not widely advertised. Bourne shell uses the notation i>&j for merging output on stream i into stream j. In this case, to merge stderr into stdout, use the notation 2>&1 as such: BMDstat $1 2>&1 As a side note, a really useful book for UNIX is "The UNIX Programming Environment" by Kernignan and Pike from Prentice-Hall. They have a discussion of stdio redirection in section "3.7 More on I/O Redirection" on p.92. --- Ciemo