[comp.unix.questions] Piping stderr in Korn and/or Bourne shell

donlash@uncle.UUCP (Donald Lashomb) (04/07/90)

In article <3620@hcx1.SSD.CSD.HARRIS.COM> brad@SSD.CSD.HARRIS.COM (Brad Appleton) writes:
[ ]
=I have a program that is supposed to read error output from other
=programs. I want to pipe stderr to this program WITHOUT piping
=stdin as well. I have not been able to find this in TFM (I have 
[ ]

This works for me:

tst 2>&1 >outfile | whatever

-Don

maart@cs.vu.nl (Maarten Litmaath) (04/07/90)

In article <12541@smoke.BRL.MIL>,
	gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
)...
)>I want to pipe stderr to this program WITHOUT piping stdin as well.
)...
)(writes_on_stderr_and_stdout 9>&1 2>&1 1>&- | cat >stderr) 1>&9 | cat >stdout

Doesn't work.  Instead try:

	$ cat foo
	echo stdout
	echo stderr >&2
	$ (sh foo 2>&1 1>&9 | cat > stderr) 9>&1 | cat > stdout
Or:
	$ sh foo 2>&1 > stdout | cat > stderr
--
 1) Will 4.5BSD have wait5()?         |Maarten Litmaath @ VU Amsterdam:
 2) Sleep(3) should be sleep(2) again.|maart@cs.vu.nl, uunet!mcsun!botter!maart

leo@atcmp.nl (Leo Willems) (04/08/90)

From article <3620@hcx1.SSD.CSD.HARRIS.COM>, by brad@SSD.CSD.HARRIS.COM (Brad Appleton):
> 
> I have a program that is supposed to read error output from other
> programs. I want to pipe stderr to this program WITHOUT piping
> stdin as well. I have not been able to find this in TFM (I have 
......
> I was hoping one of these last two might give me the output:
> 
>     this is stdout
>     this is STDerr
> 
> without piping stdin at all (just stderr)

Try this:

prog 3>&2 2>&1 1>&3 3>&- | sed 's/std/STD/'

This will swap stdout/stderr.

If you know a little C under UNIX it says:

prog close_3_dup_2 close_2_dup_1 close_1_dup_3 close_3 | sed


Hope this helps.


 Leo Willems			Internet: leo@atcmp.nl
 AT Computing			UUCP:     mcvax!hp4nl!kunivv1!atcmpe!leo
 P. O. Box 1428				
 6501 BK  Nijmegen		Phone:    +31-80-566880
 The Netherlands		Fax:	  +31-80-555887