'tee' STDERR output (ksh)

Hi everyone,

KSH question: I know you can 'tee' STDOUT to have the output go to multiple targets; can you do the same with STDERR?

For example:

ls |tee /tmp/file.txt

Will redirect STDOUT to both the screen and the '/tmp/file.txt' file. Is there a way of doing the same thing for STDERR? Ultimately what I'd like is to send STDOUT to the screen and STDERR to both the screen and a debug file.

Thank in advance for any help you can provide.

DESCRIPTION
     The tee utility will copy standard input to standard output,
     making a copy in zero or more files. tee will not buffer its
     output. The options determine if  the  specified  files  are
     overwritten or appended to.

so possably something such as this is what might do it for ya.

"your_command_here 2>&1 |tee -a stdout.log" its worth a shot.

This might do it:
prog 3>&1 >&2 2>&3 3>&- | tee errs

hi ppl,
please don't get mad at me. but why use tee in the first place

when you can do this

$ your_command >out 2> error

Perderabo, you da the man!! (of course, making a gender assumption there). That worked beautifully!! Question for you as this is the 1st time I've come accross file descriptor 3 - 1 is STDOUT, 2 is STDERR but 3? And, if you don't mind - what is the last redirection "3>&-" doing?

Thanks Perderabo!!

Asifraj - I can't use just "2> error" because then it won't also go to the screen. I want the user to know there was an error but I don't want to have to rely on them to know what the error is.

Optimus_P - while that would work for getting the errors to the screen and a file, it would also send STDOUT to the same file, which I don't want (I have a debug log that I want to contain only debug and error messages).

Thanks everyone!

I needed to reverse where stdout and stderr get their input. So I needed an extra fd. I just went with 3. 4 through 9 would have worked as well. And 3>&- just closes fd 3. At that point we're done with it, so there's no point in leaving it open while the program actually runs.

2 Likes