Unix cc and make

Is there a way to capture the errors and trace messages output by cc and make? I have tried

cc file.c > file.msg

but that doesn’t capture the error messages. Then I tried something like

cc file.c &1>file.e1 &2>file.e2 &3>file.e3

but still the error messages go to the terminal, not a file.

Any ideas?

This might be doing it the hard way but you could do

script <output file>
cc file.c
<CTRL-D>

which will capture everything just like it rolls off the screen.

You might also try

cc file.c | tee file.msg

but that might do the same as a redirect as in your first example. (Haven’t used this for a while, double check me on the “tee” spelling.)

This is a shell issue, not really an issue with cc. The question is how to redirect the stderr output stream (the simple “cc file.c > file.msg” only redirects stdout). Under the common Unix shells (Bourne and C shells) you can do
“(cc file.c > file.out) >& file.err”
to send stdout to file.out and stderr to file.err.
“cc file.c >& file.msg”
will send both stdout and stderr to file.msg (though the different buffering of stdout and stderr means that the messages might be mingled together; stderr messages will often appear earlier than you would expect).

It looks like you’re trying to use the Bourne shell file-descriptor redirections, but I don’t think you’re using quite the right syntax. It should be something like
“cc file.c 1>file.e1 2>file.e2”
to send stdout (fd 1) to file.e1 and stderr (fd 2) to file.e2.

script and tee are two commands that will send it all to a file, true.

looking at your example, though, I wonder if it’s a syntax problem.

Will cc file.c > file.e1 2>&1 work?

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

cc file.c 2>&1>file.msg

works in bash.

Or more simply, cc &> file.log.

That should be cc file.c &> file.log.