Operating System - HP-UX
1837984 Members
2693 Online
110124 Solutions
New Discussion

Re: how to catch the warning/error messages on the screen

 
SOLVED
Go to solution
Reggie Chang
Frequent Advisor

how to catch the warning/error messages on the screen

Hello there,

When I run script files (or makefiles), sometimes I got warning/error messages on the screen. How to catch those messages? I tried
to use '>' and '>>' to direct a file but it
did not work.

The info is very much appreciated.

Reggie
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: how to catch the warning/error messages on the screen

By convention, those do not go to stdout but rather to stderr.

Suppose that your command/script is called myfile.sh,

myfile.sh > mylogfile 2>myerrfile

That would output the normal messages (stdout) to mylogfile and the errors (stderr) to myerrfile.

If all you want are the errors,
myfile.sh 2>myerrfile.

If you want to send both stdout and stderr to the same file:

myfile.sh > mylogfile 2>&1

Regards, Clay
If it ain't broke, I can fix that.
Luc Bussieres
Frequent Advisor

Re: how to catch the warning/error messages on the screen

Hi,

If you are using the default shell to redirect the standard error also you should use 2> filename or 2>&1 to redirect both in the same filename.

For example:

command > filename 2>&1
will redirect all output of command to the file name filename

and

command > filename 2> filename2
will redirect the standard output to filename and the error messages to filename2.

Luc
La réponse est le malheur de la question
Michael Tully
Honored Contributor
Solution

Re: how to catch the warning/error messages on the screen

Hi,

If you wish to collect all messages that are displaying on your terminal screen you can use the script command. It will display all commands and output of these which display on your screen into a text file.

# script /tmp/myoutput
# command x
# command y
controlD to finish

HTH
-Michael
Anyone for a Mutiny ?