[comp.unix.wizards] How does one redirect just stderr under the C Shell?

rwl@franklin.ee.umr.edu (Wayne Little) (05/08/91)

From: rwl@ee.umr.edu (Wayne Little)
Newsgroups: comp.sys.unix.wizards
Subject: How to redirect just stderr under the C Shell?
References: 
Sender: 
Reply-To: rwl@ee.umr.edu (Wayne Little)
Followup-To: 
Distribution: world
Organization: University of Missouri - Rolla
Keywords: "C shell",csh, stderr, redirect

Under the C shell, I know I can redirect both stdout & stderr with
the ">&" combination;

e.g. make >& make.log

will put both the stdout and stderr ouputs in make.log.

*BUT* after all these years I still can't figure out how to redirect
*just* stderr independently of stdout under the C Shell.

Under the Bourne shell, one can just do "N>" where N is the number
of the file descriptor you want to redirect, so "2>" will redirect stderr.
e.g.  make > make.stdout 2> make.stderr

would separate the stdout from the stderr in 2 different files as indicated.

I'm at a loss under the C Shell.

Can some wizard please come to my rescue and solve this 10-year mystery
for me???

Thanks in advance,
-- 
Wayne Little  rwl@ee.umr.edu; Univ. of Missouri-Rolla EE Dept.; (314) 341-4546  
"I have read in Plato and Cicero sayings that are very wise and very beautiful;
 but I never read in either of them: "Come unto me all ye that labour and are
 heavy laden."                                                   St. Augustine

tchrist@convex.COM (Tom Christiansen) (05/08/91)

From the keyboard of rwl@ee.umr.edu (Wayne Little):
:*BUT* after all these years I still can't figure out how to redirect
:*just* stderr independently of stdout under the C Shell.

:I'm at a loss under the C Shell.

In general, it can't be done.  

Now, I'm sure someone will suggest

    ( foo > foo.stdout ) >& foo.stderr

but that's not right: stdout is mangled.   Someone else
will suggest

    ( foo > /dev/tty ) >& foo.stderr

but that's not right, as stdout is no longer going where it
had been going.  

If your system should support /dev/fd pseudo-devices, this 
ought to work:

    ( foo > /dev/stdout ) >& foo.stderr

But few of us have that feature on our systems.  


--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time." 

willcr@bud.sos.ivy.isc.com (Will Crowder) (05/09/91)

In article <1991May08.154738.26889@convex.com>, tchrist@convex.COM (Tom
Christiansen) writes:

> From the keyboard of rwl@ee.umr.edu (Wayne Little):
> > [How do I redirect stderr independent of stdout under C Shell?]
>
> In general, it can't be done.  
> 
> Now, I'm sure someone will suggest
> 
>     ( foo > foo.stdout ) >& foo.stderr
> 
> but that's not right: stdout is mangled.

How is stdout mangled?  Is it because "isatty(fileno(stdout))" will no
longer be true?

>                                            Someone else
> will suggest
>
>     ( foo > /dev/tty ) >& foo.stderr
> 
> but that's not right, as stdout is no longer going where it
> had been going.  

Now this, at least, I see.  If the above were part of a pipeline in which
stdout had already been redirected, things would go awry quite quickly, as well
as in a number of other scenarios as well, I'm sure.

Redirector emptor!  :) :) :)

|> If your system should support /dev/fd pseudo-devices, this 
|> ought to work:
|> 
|>     ( foo > /dev/stdout ) >& foo.stderr
|> 
|> But few of us have that feature on our systems.  

I sure wish my system (Sun) did!  That sounds like the right general solution
to me.

Actually, I suggested both of the above in e-mail, with the disclaimer
"I'm no wizard."  Glad I put that disclaimer on there...although I did
get mail back from Wayne saying it worked fine for his particular case.

|> --
|> Tom Christiansen		tchrist@convex.com	convex!tchrist
|> 		"So much mail, so little time." 
                 ^^^^^^^^^^^
That's why I posted this...

Will

--------------------------------------------------------------------------------
Will Crowder, MTS            | "I was gratified to be able to answer quickly,
(willcr@ivy.isc.com)         |  and I did: I said I didn't know."
INTERACTIVE Systems Corp.    |		-- Mark Twain

tchrist@convex.COM (Tom Christiansen) (05/09/91)

Quoting myself...
:If your system should support /dev/fd pseudo-devices, this 
:ought to work:
:
:    ( foo > /dev/stdout ) >& foo.stderr
:
:But few of us have that feature on our systems.  

As has been pointed out to me in mail, no, that shouldn't work.
(All I can say is that I'm one who doesn't have such a feature.)

There is, however, one tried and true way to do this:  :-)

    sh -c "cmd 2>cmd.err"

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time." 

tchrist@convex.COM (Tom Christiansen) (05/09/91)

From the keyboard of willcr@ivy.isc.com:
:In article <1991May08.154738.26889@convex.com>, tchrist@convex.COM (Tom
:Christiansen) writes:
:> 
:> Now, I'm sure someone will suggest
:> 
:>     ( foo > foo.stdout ) >& foo.stderr
:> 
:> but that's not right: stdout is mangled.
:
:How is stdout mangled?  Is it because "isatty(fileno(stdout))" will no
:longer be true?

Perhaps stolen would have been a better word choice than mangled.
Let's same it's in a script that's being run like this:

    script > script.out

The foo output no longer goes to script.out, where I expect it.

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time."