It is currently Fri, 15 Oct 2021 20:44:42 GMT

Author Message
 Redirecting stdout to More Than One Place
Sayeth (Tres Hofmeister):
$        I'm stumped.  How do I redirect standard output to more than
$one place?  What I want to do is is have both programs B and C read from
$program A's standard output.  Solutions from the command line or from
$within a script are both fine.  Thanks!

   Here are a couple of ways:

1.  Use the tee command to create a temporary file.  tee splits its
    stdin stream into two branches; one goes to the file you specify,
    the other goes to its stdout stream.  You can then attach the
    next command to the end of your pipeline, and run the third
    one separately:

a | tee /tmp/foo$$ | b
c < /tmp/foo$$
rm /tmp/foo$$

2.  Send a's stdout to a temporary file, then have both b and c use it:

a > /tmp/foo$$
b < /tmp/foo$$
c < /tmp/foo$$
rm /tmp/foo$$

   I don't know of any way to do this all in one pipeline other than
something silly like

a | tee /tmp/foo$$ | b || c < /tmp/foo$$

(or &&, depending on b's output status), but someone else might know
a better way.
.--------------------------------------.      ...!uunet!xrtll!silver
|Silver, perpetually searching for SNTF|----------------------------
`--------------------------------------'a vaguely phallic .signature

 Fri, 04 Mar 1994 00:55:40 GMT   
 Redirecting stdout to More Than One Place
In article <1991Sep15.165540.2654@xrtll> sil...@bokonon.UUCP (Hi Ho Silver) writes:
a|tee /tmp/foo$$ | b; c</tmp/foo$$; rm -f /tmp/foo$$
-How long must we fight? How long        Courtesy of Bruce Varney
 until we can live in peace.   
-Until the madmen are dead my son,      
 Or until they realize that they cannot count on us to do nothing

 Fri, 04 Mar 1994 20:18:42 GMT   
 Redirecting stdout to More Than One Place

I have a utility called tpipe that I picked up of the net a couple of
years ago, the man page is included below, which allows pipes to
constructed of the sort

a | tpipe "b >b.out" | c >c.out

which sounds like what is needed here,  I could post the source I
guess but I'm not sure of the ethics you might like to ask the author.
David B Rosen, Cognitive & Neural Systems  
Center for Adaptive Systems         rosen%bucasb@{buacca,bu-it}
Boston University      {mit-eddie,harvard,uunet}!!thalamus!rosen


TPIPE(1)            UNIX Programmer's Manual             TPIPE(1)

     tpipe - replicate the standard output into an additional
     pipeline that is run in a subshell

     tpipe [ pipeline ]

     tpipe transcribes the standard input to the standard output
     and simultaneously writes an additional copy to a specified

     tpipe is similar to tee(1) except that tpipe writes the
     duplicate copy of its standard input to a command or pipe-
     line instead of a file. This can help you avoid re-executing
     earlier commands in the pipeline, writing temporary files,
     or resorting to the use of named pipes.

     The specified pipeline is always executed in a subshell by
     sh(1), regardless of your current shell.  If a non-empty
     string is supplied as the argument, it must be a valid pipe-
     line or command for sh(1). Normally, you will want to
     enclose the pipeline argument in quotes ('' or "").  The
     type of quotes you choose will affect variable substitution
     by your shell (see the man page for your shell, such as
     csh(1), for details).

     If the subshell pipeline writes to its standard output, this
     output will go to the standard output of tpipe, where it
     will be interspersed in an unpredictable way with the other
     copy of standard input.  Normally, this is not what you
     want. Instead, you would typically specify a subshell pipe-
     line whose output is redirected to a file (as in the example
     below) or has some other effect.

          % cmd1 <infile | tpipe "cmd2 | cmd3 >outfile" | cmd4

     which has the effect of running the output of command cmd1
     simultaneously through two pipelines, "cmd2 | cmd3 >outfile"
     and cmd4.  Diagramatically, in this example (this will look
     wrong with a variable-spaced font):

                          --> cmd2 --> cmd3 --> outfile
     infile  --> cmd1 -<
                          --> cmd4 -->  (standard output)

     tee(1), sh(1), cat(1)

Printed 9/17/91          29 January 1990                        1

TPIPE(1)            UNIX Programmer's Manual             TPIPE(1)

     David B Rosen


Printed 9/17/91          29 January 1990                        2

Ian Turton                                Dept of Geophysics and geology                       JCMB, Kings Buildings
                                          Mayfield Rd, Edinburgh,UK
     ***If you don't like my views sue my boss, he'll love it.***

 Sat, 05 Mar 1994 15:56:01 GMT   
 Redirecting stdout to More Than One Place

Found on the net long ago ...

awk " { print | \"$1\" ; print }" | $2

      #       Try
      # "od -c > t1" "pr -n"
      #       The standard input will be read.
      #       The standard output will be split to
      #         1.  od -c redirected to t1
      #         2.  pr -n which will be the standard output

Marnix A. van Ammers
Pacific Bell
UUCP: ...!pacbell!pb1esac!mavanamm

 Sat, 05 Mar 1994 21:48:41 GMT   
   [ 4 post ] 

Similar Threads

1. Redirecting stdout of one program to my program

2. Redirecting output of one command to both stdout and stderr

3. Redirect stdout * stderr to one file in bourne sh using exec

4. redirecting STDOUT of a bg process to STDOUT of a new xterm

5. .redirect not redirecting to some places

6. redirecting stdio/err many times to many places

7. How to redirect from dialer-script to stdout?

8. runtime stdout redirect.

9. redirecting stdout to file over NFS slows dramatically

10. redirected stdout?

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software