Redirecting a Segfault error message to a file from a C ++ program

I get a Segfault error message that is displayed after running this command in the terminal:

   bash-3.2$ a.out < testfiles/inputs/tst1.txt 2> err.txt 
   [2]+  Done                    gedit err.txt
   Segmentation fault

a.out only runs the sorting algorithm.

My question now is how can I redirect the Seg fault error message to the err.txt file.

Using 2> or other variables does not work.

Thanks in advance.

+3
source share
2 answers

Using redirection, you cannot. This is not the output of your program, but the output of the program that launches your program. In general, a redirect would be a “Bad Idea."

0
source

It works:

$ {./a.out; } 2> err.txt
0
source

All Articles