我在我的 shell 脚本中使用的二进制文件之一导致了分段错误(返回值:139)
即使我将 stdout 和 stderr 都重定向到日志文件,当我运行 shell 脚本时,Segmentation Fault 错误消息仍会显示在终端中。
是否可以将此消息从 Segfault 重定向到日志文件?
我在我的 shell 脚本中使用的二进制文件之一导致了分段错误(返回值:139)
即使我将 stdout 和 stderr 都重定向到日志文件,当我运行 shell 脚本时,Segmentation Fault 错误消息仍会显示在终端中。
是否可以将此消息从 Segfault 重定向到日志文件?
您看到的分段错误消息由运行程序的 shell 打印。这种行为因外壳而异,因此您可以尝试一些事情(如果您坚持将分段错误消息从外壳重定向中获取到您的日志中)。
# Have sh invoke your program, and redirect output from both sh and your program into logfile
sh -c "program arguments more arguments" >logfile 2>&1
# Force bash to not just exec your program (/bin/true part), and redirect output
# from both bash and your program into logfile
bash -c "/bin/true; program arguments more arguments" >logfile 2>&1
好吧,我正在回答我自己的问题.. :) 我在这里找到了答案 How can I press the output due to a SIGSEGV or a SIGFPE in a Fortran 90 program?
诀窍是添加
`exec 2> filename`
在 shell 脚本中。
这会将所有消息从 shell 重定向到日志文件