【发布时间】:2010-02-24 20:23:33
【问题描述】:
我在我的 shell 脚本中使用的一个二进制文件导致了分段错误(返回值:139)
尽管我将 stdout 和 stderr 都重定向到日志文件,但当我运行 shell 脚本时,Segmentation Fault 错误消息仍会显示在终端中。
是否可以将此消息从 Segfault 重定向到日志文件??
【问题讨论】:
标签: bash shell segmentation-fault stdout stderr
我在我的 shell 脚本中使用的一个二进制文件导致了分段错误(返回值:139)
尽管我将 stdout 和 stderr 都重定向到日志文件,但当我运行 shell 脚本时,Segmentation Fault 错误消息仍会显示在终端中。
是否可以将此消息从 Segfault 重定向到日志文件??
【问题讨论】:
标签: bash shell segmentation-fault stdout stderr
您看到的分段错误消息是由运行您的程序的 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 suppress the output due to a SIGSEGV or a SIGFPE in a Fortran 90 program?
诀窍是添加
`exec 2> filename`
在 shell 脚本中。
这会将所有消息从 shell 重定向到日志文件
【讨论】:
【讨论】: