correct • elegant • free

△ △

◅ using mknod

remove whitespace and comments ▻

copying stderr to file?

In article <>,
J-P Theberge  <> wrote:
>javac 2>compile.error

Yes, but then you don't see standard error on the terminal.

In rc, it's easy.

    ; javac |[2] tee compile.errors >[1=2]

In sh, it's possible, but requires deep magic.  (Actually, the idea is
quite simple: create a new file descriptor, 3, which is equivalent to
standard output.  This gives us a new way to name standard output for
the duration of the pipeline, so we can redirect standard error through
the pipe.  The syntax is painful, though.)

    $ exec 3>&1; javac 2>&1 1>&3 3>&- |tee compile.errors 1>&2 3>&-

This was adapted from Tom Christiansen's csh.whynot paper.

For both versions, the output of tee is redirected to standard error
again.  This isn't important on the command line (since standard output
and standard error will be going to the same place), but it would be
essential if this were to be embedded in a script.  Also, on the command
line you probably wouldn't bother tidying up file descriptor 3.

So the least typing, command line only, versions are as follows.

    ; javac |[2] tee compile.errors

    $ exec 3>&1; javac 2>&1 1>&3 |tee compile.errors

Tim Goodwin   | "If you don't know what closures are, you probably don't
Leicester, UK | want to know what closures are." -- Larry Wall

Original headers:

From: (Tim Goodwin)
Subject: Re: copying stderr to file?
Date: 9 Feb 2000 09:19:20 -0000
Message-ID: <87rbfe$pgn$>
References: <>

△ △

◅ using mknod

remove whitespace and comments ▻