Operating System - HP-UX
1827875 Members
1390 Online
109969 Solutions
New Discussion

How to capture or replicate error and output to terminal and file?

 
SOLVED
Go to solution
Phuc Nguyen_1
Advisor

How to capture or replicate error and output to terminal and file?

I would like to replicate error and output to a file. With the tee command, I can replicate the output from the terminal into a file, but when there is an error tee can not replicate that error to the file.

example:
%lp -d printer_x file_x | tee -a log_x
%printer_x: Unknow printer
when return is an error it does not go to log_x.

Is there a built-in unix command that can replicate error and output to the terminal and file? If not, what would be another approach to this?

Thank you.
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: How to capture or replicate error and output to terminal and file?

Hi:

# $HOME/my.sh 2>&1|tee $HOME/my.log

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to capture or replicate error and output to terminal and file?

Hi:

...or using your example:

lp -d printer_x file_x 2>&1| tee -a log_x

Regards!

...JRF...
S.K. Chan
Honored Contributor

Re: How to capture or replicate error and output to terminal and file?

Yu can do ..

# lp -d printer_x file_x 2>&1 | tee -a log_x

===> log_x will capture everything plus std output and error will be shown also on terminal
S.K. Chan
Honored Contributor

Re: How to capture or replicate error and output to terminal and file?

more add-ons ..

# lp -d printer_x file_x 1>noerror.log 2>error.log
===> split error and non error log and this won't show up on terminal std output.