我有一个测试脚本,通过各种输入反复运行一个小应用程序:
# 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
Run Code Online (Sandbox Code Playgroud)
这一切都很好,除非它失败了,我得到两条消息,我想要的"错误"消息,然后另一条消息(显然来自bash?)提醒我我的应用程序已中止:
test_script.sh: line 10: 641 Aborted ./my_app $input1 $input2
ERROR: app failed with inputs: XXX YYY
Run Code Online (Sandbox Code Playgroud)
如何防止"中止"消息?
另请注意:应用程序可能在标准C库'assert'语句上失败.
我也刚碰到这个。bash如果子进程以状态码 134 返回,表明子进程 recieved ,它似乎本身会单方面打印此内容SIGABRT。解决方案是在子shell中运行子进程,然后确保子shell在失败时返回不同的(仍然是非零的)状态代码并将其输出重定向到/dev/null. 例如:
if ! ( ./myapp || false ) >/dev/null 2>&1; then
...
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2356 次 |
| 最近记录: |