LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 01-15-2007, 03:08 AM   #1
pranavchoudhary
LQ Newbie
 
Registered: Oct 2005
Location: India
Posts: 25

Rep: Reputation: 15
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
 
Old 01-15-2007, 05:41 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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, ...).
 
Old 01-15-2007, 06:10 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 01-15-2007, 06:39 AM   #4
pranavchoudhary
LQ Newbie
 
Registered: Oct 2005
Location: India
Posts: 25

Original Poster
Rep: Reputation: 15
Thumbs up

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

Thanks,
Pranav
 
Old 05-24-2007, 09:09 AM   #5
mjr1n1
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
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

Last edited by mjr1n1; 05-24-2007 at 09:16 AM.
 
Old 05-24-2007, 09:18 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

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

Hope this clears things up.
 
Old 05-24-2007, 09:28 AM   #7
mjr1n1
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
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
 
Old 08-25-2008, 01:57 AM   #8
youthanasia78
LQ Newbie
 
Registered: Aug 2008
Posts: 1

Rep: Reputation: 0
This information was very useful. Thanks!
 
  


Reply

Tags
error, file, standard


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script - stdout & stderr to terminal and file jantman Linux - Software 1 12-07-2006 04:34 PM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 06:55 AM
shell short question(stdout, stderr) blackzone Programming 4 11-11-2004 09:01 AM


All times are GMT -5. The time now is 10:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration