redirection of ./a.out is not capturing segmentati

2019-04-24 06:06发布

I run the command

./a.out < in &> output.txt
I want the errors also to be placed in output.txt.
The exit status of the command was 139 and on terminal its output was:

Segmentation fault (core dumped)

and the file output.txt was empty.

2条回答
趁早两清
2楼-- · 2019-04-24 06:37

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

Segmentation fault (core dumped)

to be appended to output.txt, then you have to redirect the shell's stderr as well. E.g.,

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

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

查看更多
Root(大扎)
3楼-- · 2019-04-24 06:41

The message Segmentation fault (core dumped) is not coming from your program.

It's produced by shell as result of a signal received by it. It's not a part of stderr or stdout of your program.

So shell's message can be captured as:

{ ./a.out; } 2> out_err 
查看更多
登录 后发表回答