combined stdout & stderr

Hello Everyone!
I'm trying to combine output for standard output and for possible standard error to the log file. I was trying to use tee command, but it turned out if error occurred error output will be send to the screen only and will not be redirected with tee command to the log file.
Anyone knows how to make log file to record all possible output including stderr?

Many thanks in advance.

Depends on the shell. For sh, ksh, and bash it's:
some_program > logfile 2>&1

It's a C shell. BTW, I thought, that 2>&1 redirect stderr only to sdtout. Am I wrong?
Thanks.

2>&1 sends stderr to the same place as stdout. Thus combining them as requested. But this only works with real shells. For csh it's

command >& file

Thank you Perderabo for the reply. Seems to me both 2>&1 and >& redirect stderr to file and work fine in C shell, however the problem is that no stdout send to terminal - all output redirected to log file. I would like both outputs to be displayed on the terminal, and both of them redirected to log file ( including errors) at same time. Something like tee command which splits output and allow me to see output on the screen and have it in the log file simultaneously. But the problem with tee, that it can handle stdout only and cannot handle stderr.
If I misunderstood your suggestion, please explain it again.

Thanks,

Something like this will work for bash

((./myscript arg1 arg2 | tee stdout) 3>&1 1>&2 2>&3 | tee stderr)

This will create two files, stdout and stderr containing the expected output, plus all output will also appear on screen. Replace ./myscript arg1 arg2 with the actual command you're using.

Cheers
ZB

Thank you for the reply.
Nop, unfortunately it does not work, zazzybob. Does C Shell understand 3>&1 1>&2 2>&3?
I'm getting �Ambiguous output redirect�. And I'm getting the same error message while I was trying different combinations of >& and tee... which means to me C shell does not want to see anything after >&. Or I'm able to create log file with stderr in it, but getting nothing to terminal window. I could not imagine it would be so tricky...

As I stated above, the code works bash - do you really need to use the C shell? Could you not encompass the above command inside a bash script?

Cheers
ZB

Yes, I really have to use C Shell. It is official company shell and because of this all my scripts (including this ) are run in C shell.

Thanks,

Folks!
Looks like I found the solution for C Shell. It would be:

command argument |& tee filename.log

Thanks everyone!

Does anyone know an answer for this in ksh?

Here is what I am trying to do. See how the output of time does not show up in the log.

$ time ls home test 2>&1 | tee -a test.log
ls: 0653-341 The file home does not exist.
test

real 0m0.01s
user 0m0.00s
sys 0m0.02s
$ cat test.log
ls: 0653-341 The file home does not exist.
test