执行“./a.out”时如何重定向"Aborted (core dumped)"等信息
How to redirect info like "Aborted (core dumped)" when execute "./a.out"
有一个.out文件,当运行时会导致Aborted (core dumped)
信息。
我想把这个信息Aborted (core dumped)
放到一个文件中。
其实我想把它放到我的程序中,但是我有重定向问题。一旦这个问题解决了,我就可以通过重定向和popen()把它放到我的程序中了。
我试了./a.out 2>file
,但是没用。
重定向 a.out
的标准错误不会执行任何操作,因为 a.out
实际上并未写入 Aborted (core dumped)
消息。此消息在您的流程中写成 by the shell itself in response to an abnormal status returned when it calls waitpid
或类似内容。
为了以编程方式获取相同的信息,您需要检查将出现在 $?
中的退出代码。信号 11 (SIGSEGV) 将导致退出代码 128+11=139; SIGABRT(信号 6)应导致退出代码 134。
有一个.out文件,当运行时会导致Aborted (core dumped)
信息。
我想把这个信息Aborted (core dumped)
放到一个文件中。
其实我想把它放到我的程序中,但是我有重定向问题。一旦这个问题解决了,我就可以通过重定向和popen()把它放到我的程序中了。
我试了./a.out 2>file
,但是没用。
重定向 a.out
的标准错误不会执行任何操作,因为 a.out
实际上并未写入 Aborted (core dumped)
消息。此消息在您的流程中写成 by the shell itself in response to an abnormal status returned when it calls waitpid
或类似内容。
为了以编程方式获取相同的信息,您需要检查将出现在 $?
中的退出代码。信号 11 (SIGSEGV) 将导致退出代码 128+11=139; SIGABRT(信号 6)应导致退出代码 134。