gururaj gururaj - 1 year ago 43
Perl Question

Suppress gcc output to terminal when using only preprocessor

I am using the preprocessor of gcc to remove the comments from a verilog (.v) file (since the comment syntax is same as C/C++). I am using perl and hence used a shell command from my perl script

gcc -E $dest > $commentsrem

is my verilog file renamed as a .c file.
Since the preprocessor outputs data onto stdout, I redirected it to a file named
Now the problem I face is that I get messages on the terminal saying

try.c:577: unterminated character constant

I guess this is because although in C you need to use '\' to continue a statement on a new line, verilog has no such requirement. That is what it is reporting.

Now although in spite of these, it achieves what I want, it's making the terminal messy. Any way to keep it quiet?


Redirecting standard error to the null device would silence all error output from the preprocessor. Not generally recommended, as you will not see genuine errors either.

gcc -E $dest > $commentsrem 2> /dev/null

The better way would be to filter known messages from the stderr by use of grep -v, so you would still see other error messages. For this, you need to redirect stderr to stdout, because piping doesn't work on stderr:

gcc -E $dest 2>&1 > $commentsrem | grep -v "unterminated character constant"

The order of the redirections is important here. If you wrote > $commentsrem 2>&1, the error messages would end up in $commentsrem instead.

For details on the redirecting, ref. this Q/A.