stderr & csh

Craig Schreiner craig at aspect.UUCP
Wed Dec 13 04:32:00 AEST 1989



>      This question may sound DUMB, but please read it!!!!!!
> Using CSH, how do you redirect ONLY stderr?  Before you all say
> "idiot, just use >&", try this program.......
> 
> 
> #include "stdio.h"
> /* to compile:  cc -o erronly erronly.c */
> /* to run:      erronly >& outfile      */
> main()
> {
> 	fprintf(stderr, "I know you won't believe me ");
> 	fprintf(stdout, "until you read this file!!\n");
> }
> 
> 
>      As stated in THE UNIX C SHELL FIELD GUIDE, written by Gail Anderson &
> Paul Anderson, on page 64, ">& also redirects the standard output".


If you look again on the top of page 64 you will note the statement:

% (find / -name vi -print > /dev/tty) >& /dev/null

Essentially you use the () as a command group and redirect its standard
output and then redirect it again for standard error.  Since standard
output has already been redirected the only thing left is the standard
error.  To run your erronly program you need to issue the command as:

% (erronly >stdout) >& stderr

to get the results you are looking for!

     I believe that this question has been answered many times and
is in the general postings of news.newusers.questions or in
news.announce.newusers.



More information about the Comp.unix.questions mailing list