[comp.sources.wanted] separate redirection of stderr and stdout in csh.

jeffy@teraida.UUCP (Jeffrey Youngstrom) (11/17/89)

Hiya,
	In the bourne shell I can do this:

		#!/bin/sh

		dumb_command 1> good_stuff 2> errors

	to send the output of my command to good_stuff, and
	any error messages to a file called errors.

	How the heck do you do this for csh?!!!

	And don't say "well it's easy if you use perl"!!! :-)

Thanks in advance.
jeffy


-- 
        ...!{decwrl,sun}!teraida!jeffy or jeffy@altair.csustan.edu
    "It's a beautiful world if people would just look!" -- my Grandma
   "Everything has its beauty, but not everyone sees it." -- Confucius
Read it in the books in the crannies and the nooks there are books to read

pricked@vax1.acs.udel.EDU (Jenn-Ming Yang) (11/17/89)

In article <13928@teraida.UUCP> jeffy@teraida.UUCP (Jeffrey Youngstrom) writes:
>Hiya,
>	In the bourne shell I can do this:
>		#!/bin/sh
>		dumb_command 1> good_stuff 2> errors
>	to send the output of my command to good_stuff, and
>	any error messages to a file called errors.
>	How the heck do you do this for csh?!!!


This works on BSD 4.3:

 (a.out > stout) >& sterr

sterr will contain only stuff written to stderr,
stout will only contain stuff written to stdout.
(provided to don't screw around with closing and opening stderr and stdout
 in certain ways).

 This also works:
  (a.out > xyz) |& tee abc




-- 
Send e-mail to:
pricked@vax1.acs.udel.edu (or pricked@192.5.57.1, pricked@192.5.57.129)
!!!!!!!!!!!!!!!!!!!!!!!!There is no substitute!!!!!!!!!!!!!!!!!!!!!!!!!
!!played lums pond? why not? are you weak or do you just have brains?!!

kevin@cbmvax.UUCP (Kevin Klop) (11/17/89)

In article <13928@teraida.UUCP> jeffy@teraida.UUCP (Jeffrey Youngstrom) writes:
>Hiya,
>	In the bourne shell I can do this:
>
>		#!/bin/sh
>
>		dumb_command 1> good_stuff 2> errors
>
>	to send the output of my command to good_stuff, and
>	any error messages to a file called errors.
>
>	How the heck do you do this for csh?!!!
>
>	And don't say "well it's easy if you use perl"!!! :-)

well, dumb_command >&somestuff

will redirect stderr out to somestuff.  It has the unfortunate side effect
of ALSO redirecting stdout as well.  I don't believe that there's a way
to affect this.

                              -- Kevin Klop --

montnaro@sprite.crd.ge.com (Skip Montanaro) (11/17/89)

How about 

	(dumb_command > good_stuff) >& errors

This question is probably better handled in comp.unix.questions.

--
Skip Montanaro (montanaro@crdgw1.ge.com)

pricked@vax1.acs.udel.EDU (Jenn-Ming Yang) (11/17/89)

In article <8607@cbmvax.UUCP> kevin@cbmvax.UUCP (Kevin Klop) writes:
>In article <13928@teraida.UUCP> jeffy@teraida.UUCP (Jeffrey Youngstrom) writes:
>>Hiya,
>>	In the bourne shell I can do this:
>>		#!/bin/sh
>>		dumb_command 1> good_stuff 2> errors
>>	to send the output of my command to good_stuff, and
>>	any error messages to a file called errors.
>>	How the heck do you do this for csh?!!!
>>	And don't say "well it's easy if you use perl"!!! :-)
>well, dumb_command >&somestuff
>will redirect stderr out to somestuff.  It has the unfortunate side effect
>of ALSO redirecting stdout as well.  I don't believe that there's a way
>to affect this.

Sure is(at least on BSD 4.3 unix, no access to other unix types)

   (dumb_command > goodstuff) >& errors

ALL stdout goes to 'goodstuff', ALL stderr goes to 'errors'.
You can do it using pipes also.

I didn't see my earlier post. Maybe it got sucked away by a blackhole.






-- 
Send e-mail to:
pricked@vax1.acs.udel.edu (or pricked@192.5.57.1, pricked@192.5.57.129)
!!!!!!!!!!!!!!!!!!!!!!!!There is no substitute!!!!!!!!!!!!!!!!!!!!!!!!!
!!played lums pond? why not? are you weak or do you just have brains?!!

jeffy@teraida.UUCP (Jeffrey Youngstrom) (11/18/89)

In article <MONTNARO.89Nov17073713@sprite.crd.ge.com> <montanaro@crdgw1.ge.com> (Skip Montanaro) writes:
>How about 

>	(dumb_command > good_stuff) >& errors

	This works nicely, thank you very much.
	And thanks too to all you other folks who replied.

>This question is probably better handled in comp.unix.questions.

	Right you are...  sorry about that.

>Skip Montanaro (montanaro@crdgw1.ge.com)

Thanks again gang!

jeffy
-- 
        ...!{decwrl,sun}!teraida!jeffy or jeffy@altair.csustan.edu
    "It's a beautiful world if people would just look!" -- my Grandma
   "Everything has its beauty, but not everyone sees it." -- Confucius
Read it in the books in the crannies and the nooks there are books to read

ted@bangles.sgi.com (Ted Wilcox) (11/18/89)

In article <13928@teraida.UUCP>, jeffy@teraida.UUCP (Jeffrey Youngstrom)
writes:
> Hiya,
> 	In the bourne shell I can do this:
> 
> 		#!/bin/sh
> 
> 		dumb_command 1> good_stuff 2> errors
> 
> 	to send the output of my command to good_stuff, and
> 	any error messages to a file called errors.
> 
> 	How the heck do you do this for csh?!!!
> 
> 	And don't say "well it's easy if you use perl"!!! :-)
> 
> Thanks in advance.
> jeffy

From my friendly neighborhood csh man page:

"To redirect standard output and standard error to separate files, use
(cmd > file1) >& file2"

Hope this is what you wanted.


Ted.
ted@sgi.com
{sun|decwrl|pyramid|ucbvax}!sgi!ted

merlyn@iwarp.intel.com (Randal Schwartz) (11/18/89)

In article <13928@teraida.UUCP>, jeffy@teraida (Jeffrey Youngstrom) writes:
| Hiya,
| 	In the bourne shell I can do this:
| 
| 		#!/bin/sh
| 
| 		dumb_command 1> good_stuff 2> errors
| 
| 	to send the output of my command to good_stuff, and
| 	any error messages to a file called errors.
| 
| 	How the heck do you do this for csh?!!!
| 
| 	And don't say "well it's easy if you use perl"!!! :-)

OK, I won't!  (And actually, it's not even that easy :-)

First, I could say, just use /bin/sh.  But, at the expense of
forking a second csh, you can do it with csh, as in:

% (dumb_command >good_stuff) >&errors

It works.

(Isn't this in a "Frequently Asked Questions" posting somewhere?)

Just another C-shell despiser,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/

karish@forel.stanford.edu (Chuck Karish) (11/18/89)

In article <MONTNARO.89Nov17073713@sprite.crd.ge.com>
<montanaro@crdgw1.ge.com> (Skip Montanaro) wrote:
>How about 
>
>	(dumb_command > good_stuff) >& errors

This forks a subshell.  It's a Bourne shell, as written here.
The `errors' file gets the stderr of the Bourne shell, not of
the `dumb_command' process.

The real answer to the question is "You can't do it in csh".

	Chuck Karish		karish@mindcraft.com
	(415) 323-9000		karish@forel.stanford.edu

greywolf@unisoft.UUCP (The Grey Wolf) (11/18/89)

In article <8607@cbmvax.UUCP> kevin@cbmvax.UUCP (Kevin Klop) writes:
>In article <13928@teraida.UUCP> jeffy@teraida.UUCP (Jeffrey Youngstrom) writes:
>>Hiya,
>>	In the bourne shell I can do this:
>>
>>		#!/bin/sh
>>
>>		dumb_command 1> good_stuff 2> errors
>>
>>	to send the output of my command to good_stuff, and
>>	any error messages to a file called errors.
>
>well, dumb_command >&somestuff [ works for csh...almost -- greywolf ]
>
>will redirect stderr out to somestuff.  It has the unfortunate side effect
>of ALSO redirecting stdout as well.  I don't believe that there's a way
>to affect this.
>
>                              -- Kevin Klop --

Try this:

	( dumb_command > good_stuff) >& errors
-- 
"Insane I may be.  I am not stupid."	Antryg Windrose <the mad wizard>
-- 
"Insane I may be.  I am not stupid."	Antryg Windrose <the mad wizard>

fyl@fylz.UUCP (Phil Hughes) (11/19/89)

In article <13928@teraida.UUCP>, jeffy@teraida.UUCP (Jeffrey Youngstrom) writes:
> Hiya,
> 	In the bourne shell I can do this:
> 
> 		#!/bin/sh
> 
> 		dumb_command 1> good_stuff 2> errors
> 
> 	How the heck do you do this for csh?!!!

I hate to give away one of the "tricks" from the Unix for Programmers
class that I teach but someone else will tell you anyway so here it
is:

First, you can't.  csh doesn't allow it.  But, being a creative person
you can always do what you want with UNIX.  So, try:

	(dumb_command >good_stuff) >& errors

It works because standard out from the command is redirected to
good_stuff within the subshell.  Then, everything (that is left) is
redirected to errors.

-- 
Phil Hughes - FYL - 8315 Lk City Wy NE - Suite 207 - Seattle, WA 98115
	(206)526-2919 or LAMB-919 for the strange	
{amc-gw,uunet!pilchuck}!ssc!fylz!fyl

deven@rpi.edu (Deven T. Corzine) (11/27/89)

As many people pointed out, the following works:

   (dumb_command > good_stuff) >& errors

However, I don't believe it is possible to redirect stderr while
piping stdout to another command...  (Yes, you could put the entire
pipeline in a subshell, but you can't have just one command from the
pipeline have its stderr split away...)

Ah, well.

Deven
-- 
Deven T. Corzine        Internet:  deven@rpi.edu, shadow@pawl.rpi.edu
Snail:  2151 12th St. Apt. 4, Troy, NY 12180   Phone:  (518) 274-0327
Bitnet:  deven@rpitsmts, userfxb6@rpitsmts     UUCP:  uunet!rpi!deven
Simple things should be simple and complex things should be possible.

merlyn@iwarp.intel.com (Randal Schwartz) (11/28/89)

In article <DEVEN.89Nov26112903@netserv2.rpi.edu>, deven@rpi (Deven T. Corzine) writes:
| 
| As many people pointed out, the following works:
| 
|    (dumb_command > good_stuff) >& errors
| 
| However, I don't believe it is possible to redirect stderr while
| piping stdout to another command...  (Yes, you could put the entire
| pipeline in a subshell, but you can't have just one command from the
| pipeline have its stderr split away...)

Sure you can.  Lean on /bin/sh --

% comm1 arga argb | /bin/sh -c 'comm2 arga argb 2>errors' | comm3 arga argb

"Magic is easy, once *you* know the secret..."  :-)
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/

jmm@eci386.uucp (John Macdonald) (11/28/89)

In article <DEVEN.89Nov26112903@netserv2.rpi.edu> deven@rpi.edu (Deven T. Corzine) writes:
>
>As many people pointed out, the following works:
>
>   (dumb_command > good_stuff) >& errors
>
>However, I don't believe it is possible to redirect stderr while
>piping stdout to another command...  (Yes, you could put the entire
>pipeline in a subshell, but you can't have just one command from the
>pipeline have its stderr split away...)

Well, it actually is possible, but even more than the "double-redirect
using a sub-shell" solution, you have to shuffle things around and
cheat a little bit.  You use a named pipe!

    If you wanted (in sh-syntax):
	com1 | com2 2>com2.err | com3
    You would write (in csh):
	mknod pipe$$ p
	com3 <pipe$$
	(com1 | com2 >pipe$$) >&com2.err
	rm pipe$$
    This is sufficiently contorted (and I always have to experiment to
    be sure that I am using a named pipe right) that I would normally
    instead write (in csh):
	sh -c 'com1 | com2 2>com2.err | com3'
-- 
80386 - hardware demonstrating the fractal nature of warts.   | John Macdonald
EMS/LIM - software demonstrating the fractal nature of warts. |   jmm@eci386

brnstnd@stealth.acf.nyu.edu (Dan Bernstein) (11/28/89)

In article <1989Nov27.171928.17527@eci386.uucp> jmm@eci386.UUCP (John Macdonald) writes:
> mknod pipe$$ p
> com3 <pipe$$
> (com1 | com2 >pipe$$) >&com2.err
> rm pipe$$

The shell will block trying to open pipe$$ for the second command's
input. Put that command in the background.

What happened to trying things out before posting them?

Enough discussion already. Followups to sci.aquaria.

---Dan

MBT3@PSUVM.BITNET (Mike Tierney) (12/01/89)

Ginger Rogers... for real!

deven@rpi.edu (Deven T. Corzine) (12/02/89)

On 1 Dec 89 11:01:05 GMT, MBT3@PSUVM.BITNET (Mike Tierney) said:

Mike> Ginger Rogers... for real!

Um, huh?
-- 
Deven T. Corzine        Internet:  deven@rpi.edu, shadow@pawl.rpi.edu
Snail:  2151 12th St. Apt. 4, Troy, NY 12180   Phone:  (518) 274-0327
Bitnet:  deven@rpitsmts, userfxb6@rpitsmts     UUCP:  uunet!rpi!deven
Simple things should be simple and complex things should be possible.