[comp.unix.questions] stderr & csh

skeeve@eng.umd.edu (Rebecca J. Oakes) (12/07/89)

     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".
-- 
      //\                       |  _
      \\                        | /^\ - Cyber Spud 
     \// keeve@wam.umd.edu      | \_/   -- The Augmented Potatoe
                                |
"Life is a series of rude awakenings." - R. V. Winkle

skeeve@eng.umd.edu (Rebecca J. Oakes) (12/07/89)

     Thanks for your mail.  I received quite a few different
solutions.  I feel the best is:

     (command > /dev/tty) >& outfile

     This redirects stdout to /dev/tty.  Then everything thats leftover,
namely stderr, gets redirected to outfile.

-- 
      //\                       |  _
      \\                        | /^\ - Cyber Spud 
     \// keeve@wam.umd.edu      | \_/   -- The Augmented Potatoe
                                |
"That's entertainment!" - Vlad the Impaler

gwyn@smoke.BRL.MIL (Doug Gwyn) (12/07/89)

In article <1989Dec7.025716.2507@eng.umd.edu> skeeve@eng.umd.edu writes:
>     This question may sound DUMB, but please read it!!!!!!
>Using CSH, how do you redirect ONLY stderr?

The REAL reason it's a dumb question is that it's answered
in the "frequently asked questions" list that you're supposed
to check before posting your question.

fyl@ssc.UUCP (Phil Hughes) (12/09/89)

:-)
-- 
Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155  (206)FOR-UNIX
    amc-gw!ssc!fyl or uunet!pilchuck!ssc!fyl or attmail!ssc!fyl

craig@aspect.UUCP (Craig Schreiner) (12/13/89)

>      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.