The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
redirecting STDOUT & STDERR jshinaman Shell Programming and Scripting 9 06-21-2007 09:04 PM
precedence of stderr and stdout new2ss Shell Programming and Scripting 1 06-08-2006 08:03 PM
How to use tee with stdout and stderr? siegfried Shell Programming and Scripting 1 11-17-2005 11:07 PM
STDOUT and STDERR going to a system log longyie904 Shell Programming and Scripting 1 09-11-2002 08:42 PM
Redirect stdout and stderr zcurtis Shell Programming and Scripting 8 09-02-2002 03:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-18-2004
Registered User
 

Join Date: Aug 2004
Location: California
Posts: 14
Stumble this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-18-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
Depends on the shell. For sh, ksh, and bash it's:
some_program > logfile 2>&1
Reply With Quote
  #3 (permalink)  
Old 11-19-2004
Registered User
 

Join Date: Aug 2004
Location: California
Posts: 14
Stumble this Post!
It's a C shell. BTW, I thought, that 2>&1 redirect stderr only to sdtout. Am I wrong?
Thanks.
Reply With Quote
  #4 (permalink)  
Old 11-19-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
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
Reply With Quote
  #5 (permalink)  
Old 11-22-2004
Registered User
 

Join Date: Aug 2004
Location: California
Posts: 14
Stumble this Post!
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,
Reply With Quote
  #6 (permalink)  
Old 11-22-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
Something like this will work for bash
Code:
((./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
Reply With Quote
  #7 (permalink)  
Old 11-22-2004
Registered User
 

Join Date: Aug 2004
Location: California
Posts: 14
Stumble this Post!
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…
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0