LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   send stderr to a file and also to stdout (https://www.linuxquestions.org/questions/linux-newbie-8/send-stderr-to-a-file-and-also-to-stdout-519385/)

pranavchoudhary 01-15-2007 03:08 AM

send stderr to a file and also to stdout
 
Hi,

If i am running some program, say make, and want all that is printed to stderr(but not stdout) also to go to a file (and get printed on the stdout as well), how do i do it?

I found 'tee', bit i am looking for its stderr counterpart!!

thanks,
pranav

timmeke 01-15-2007 05:41 AM

If you don't need the stdout messages, you could do:
Code:

make 2>&1 >/dev/null | tee your_file
Note that the order (ie first 2>&1) is important: 2>&1 must be put BEFORE >/dev/null, otherwise your error messages will be sent to /dev/null.

Alternatively, you might consider named FIFO pipes. See "man mkfifo".

And there is no "stderr counterpart" to tee. tee just copies whatever it gets on it's stdin to it's stdout and to a file. What it gets on it's stdin can come from anywhere (another programs stdout, stderr, a file, ...).

druuna 01-15-2007 06:10 AM

Hi,

make 3>&1 1>&2 2>&3 | tee stderr.txt

The above will:

Show normal text on screen,
Show error text on screen,
Put error text in file.

This is done by reassigning your file descriptors stdout will become stderr and stderr will become stdout. tee (which only works in stdout) will put the reassigned stderr to file.

Hope this is what you are looking for.

pranavchoudhary 01-15-2007 06:39 AM

The idea of reassigning stderr to stdout and vice-versa works.

Thanks,
Pranav

mjr1n1 05-24-2007 09:09 AM

I am trying the same command...in a c-shell script and it doesn't work...

!#/bin/csh -f

make 3>&1 1>&2 2>&3 | tee build.err

It gives 'ambiguous output redirect" error..


the only thing that works in a c-shell is this..

make >& build.err

which puts both stdout and stderr in a file. I could not find a way to just redirect stderr to a file and not both.

any suggestions ?




-mjr

druuna 05-24-2007 09:18 AM

Hi,

Too my knowledge this cannot be done with (t)csh.

Hope this clears things up.

mjr1n1 05-24-2007 09:28 AM

Well... I figured out something of a workaround to put stdout and stderr in different files when
using a C-shell.

( make > build.out ) >& build.err

this works.

any other suggestions..

-mjr

youthanasia78 08-25-2008 01:57 AM

This information was very useful. Thanks!


All times are GMT -5. The time now is 05:43 PM.