[Techtalk] Using > to redirect standard error?

Kathryn Hogg kjh at flyballdogs.com
Tue Jan 13 23:05:03 EST 2004


Rachel McConnell said:
> In fact it works on cygwin!  Thanks much.  The regular messages, what I
> called stdout, appear to be suppressed entirely using 2>, although for
> my purposes this is fine.  "second redirect operator"  I'll do some
> research on that; I never knew such a thing existed.

I've never heard of the term "second redirect operator".  It's just
generic file descriptor (fd) redirection.  The general form is fd > dest 
where

fd = is the file descriptor that you wish to redirect.  0 = stdin, 1 =
stdout, 2 = stderr.  If not specified, fd defaults to 1   It's not limited
to those 3.  I remember lp print spoolers that would have the printer
device opened on fd 5 for example.

dest = file name like foo.txt or &fd where fd is another file descriptor.
i.e. 2>&1 says redirect fd 2 to go wherever fd #1 is going.

As someone else pointed out, command >foo.txt 2>&1 will redirect stdout
(fd 1) to file foo.txt and then redirect stderr (fd 2) to wherever fd 1 is
going (foo.txt)

Note that this is NOT equivalent to

command >foo.txt 2>foo.txt

In this method, stdout and stderr are not tied to each other so there is
no guarantee that writing to stdout followed by writing to stderr will
actually end up in the file in the same order as called.

-- 
Kathryn
http://womensfootyusa.com


More information about the Techtalk mailing list