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.
source share