加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

防止bash打印“Aborted”消息

发布时间:2020-12-16 01:17:58 所属栏目:安全 来源:网络整理
导读:我有一个测试脚本,它通过各种输入反复运行一个小应用程序: # test_script.shfor input1 in $some_range; do for input2 in $some_other_range; do if ! ./my_app $input1 $input2 2/dev/null; then echo "ERROR: app failed with inputs: $input1 $input2"
我有一个测试脚本,它通过各种输入反复运行一个小应用程序:
# test_script.sh

for input1 in $some_range; do
    for input2 in $some_other_range; do
        if ! ./my_app $input1 $input2 2>/dev/null; then
            echo "ERROR: app failed with inputs: $input1 $input2"
        fi
    done
done

这一切都很好,除非它失败了,我得到两条消息,我想要的“错误”消息,然后另一条消息(显然是来自bash?)提醒我我的应用程序已中止:

test_script.sh: line 10:   641 Aborted           ./my_app $input1 $input2
ERROR: app failed with inputs: XXX YYY

如何防止“中止”消息?

另请注意:应用程序可能在标准C库’assert’语句上失败.

我也碰到了这个.如果子进程返回状态代码134,表明孩子收到了SIGABRT,那么bash本身就会单方面打印出来.解决方案是在子shell中运行子进程,然后确保子shell在失败时返回不同的(仍为非零)状态代码,并将其输出重定向到/ dev / null.例如:
if ! ( ./myapp || false ) >/dev/null 2>&1; then
    ...
fi

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读