问题描述
我使用的程序可以正常运行,并且在运行结束时会产生理想的输出,而不会发生内存泄漏或任何其他特定问题,但是随后它在退出时发出了分段错误.我一直在尝试通过使用标准程序将标准错误重定向到Null来向最终用户隐藏此无害但烦人的错误:
I use a program that works properly and results in desirable output at the end of its operation with no memory leak or any other specific issue, but then it issues a segmentation fault at the point it exits. I have been trying to hide this harmless but annoying error from the end user when using this program by redirecting the standard error to Null:
program options >file 2>/dev/null
但是这不起作用,并且每次我运行程序时,错误都会显示在脚本输出的中间.这里到底发生了什么,如何隐藏不需要的错误?我在优胜美地上.
But this doesn't work and the error shows up in the middle of the script's outputs each time I run the program. What is exactly happening here, and how can I hide the unwanted error? I'm on Yosemite.
推荐答案
来自坏主意部门:
program options >file 2>/dev/null | cat
bash似乎不会抱怨其输出通过其他途径传递的程序中的分段错误.因此,只需将输出输出到任何地方即可. cat
是一个不错的选择,因为它只是回显已发送的文本.或通过管道传递到null命令:
,以便可以在脚本中放置表情符号:
It seems that bash won’t complain about segmentation faults in programs whose output is piped elsewhere. So just pipe your output anywhere. cat
is a good choice, since it just echos the text it was sent. Or pipe to the null command, :
, so you can put an emoji in your script:
program options >file 2>/dev/null |:
很明显,这可以掩盖其他更严重的问题,因此,如果可能的话,您应该修复分段错误.
It should be obvious that this can hide other, more severe problems, and so you should fix the segmentation fault if at all possible.
这篇关于如何在bash脚本中隐藏分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!