Redirecting. / A.out does not fix segmentation error

I ran a command

  ./a.out <in &> output.txt 
I want errors to also be posted in output.txt .
The exit command status was 139, and its output on the terminal:
  Segmentation fault (core dumped) 

and the output.txt file was empty.

+6
source share
2 answers

The Segmentation fault (core dumped) message does not come from your program.

It is created by the shell as a result of receiving a signal. This is not part of the stderr or stdout of your program.

So a shell message can be written as:

 { ./a.out; } 2> out_err 
+16
source

If you want both error messages from a.out and string

 Segmentation fault (core dumped) 

which will be added to output.txt , then you should also redirect the stderr shell. For instance.

 exec 2>> output.txt && ./a.out < in 2>&1 >> output.txt & 

This is because the segfault message comes from the shell itself.

+4
source

Source: https://habr.com/ru/post/970082/


All Articles