Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conceal a segmentation fault in a bash script

I use a program that works properly and results in desirable output at the end of its operation with no memory leak or any other specific issue, but then it issues a segmentation fault at the point it exits. I have been trying to hide this harmless but annoying error from the end user when using this program by redirecting the standard error to Null:

program options >file 2>/dev/null

But this doesn't work and the error shows up in the middle of the script's outputs each time I run the program. What is exactly happening here, and how can I hide the unwanted error? I'm on Yosemite.

like image 346
retrography Avatar asked Mar 18 '23 01:03

retrography


1 Answers

From the Bad Idea Department:

program options >file 2>/dev/null | cat

It seems that bash won’t complain about segmentation faults in programs whose output is piped elsewhere. So just pipe your output anywhere. cat is a good choice, since it just echos the text it was sent. Or pipe to the null command, :, so you can put an emoji in your script:

program options >file 2>/dev/null |:

It should be obvious that this can hide other, more severe problems, and so you should fix the segmentation fault if at all possible.

like image 99
yellowantphil Avatar answered Mar 24 '23 09:03

yellowantphil