Prevent bash from printing “<PID> Aborted” messages
I've got a test script that runs a small app over and over again with various inputs:
# 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
This is all well and good, except when it fails I get two messages, the 'ERROR' message I want, and then another (apparently from bash?) alerting me that my app was aborted:
test_script.sh: line 10: 641 Aborted ./my_app $input1 $input2
ERROR: app failed with inputs: XXX YYY
How do I prevent the开发者_高级运维 'Aborted' messages?
Also note: The app is probably failing on a standard C library 'assert' statement.
I just ran into this too. It seems that bash
itself prints this unilaterally if a child process returns with status code 134, indicating the child recieved SIGABRT
. The solution is to run the child process in a subshell, then ensure the subshell returns a different (still non-zero) status code on failure and has its output redirected to /dev/null
. For example:
if ! ( ./myapp || false ) >/dev/null 2>&1; then
...
fi
Try disabling job control:
set +m
you can redirect stderr to /dev/null
./myapp .... 2>/dev/null
You probably should not suppress the error message. Instead of having your script emit an error message and suppress the error from the app, have the script say nothing and let the app's error message print. If you don't like the error message from the app, fix it in the app rather than trying to have the script patch it.
You can use $()
to wrap your commands, for example:
$($app &> /dev/n
精彩评论