tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ using mknod

remove whitespace and comments ▻

copying stderr to file?

In article <x7900veio6.fsf@godzilla.act.oda.fr>,
J-P Theberge  <jphil@act.oda.fr> wrote:
>javac test.java 2>compile.error

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

In rc, it's easy.

    ; javac test.java |[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 test.java 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 test.java |[2] tee compile.errors

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

Tim.
--
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: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: copying stderr to file?
Date: 9 Feb 2000 09:19:20 -0000
Message-ID: <87rbfe$pgn$1@ltpcg.star.le.ac.uk>
References: <38A04B3D.1BF33F76@trcinc.com>
  <x7900veio6.fsf@godzilla.act.oda.fr>

△ comp.unix.shell △

◅ using mknod

remove whitespace and comments ▻