Skip to content

Instantly share code, notes, and snippets.

@soonhokong
Last active August 29, 2015 14:15
Show Gist options
  • Save soonhokong/0fe364a343694c788e05 to your computer and use it in GitHub Desktop.
Save soonhokong/0fe364a343694c788e05 to your computer and use it in GitHub Desktop.
exit_code_wrapper.sh
#!/usr/bin/env bash
#
# Usage: ./exit_code_wrapper.sh /path/to/dReal /path/to/smt2 option_to_dReal1 option_to_dReal2 option_to_dReal3 ...
#
# Return:
#
# 51 if smt2 is SAT
# 52 if smt2 is UNSAT
# 1 if there is any error
#
# Author: Soonho Kong <soonhok@cs.cmu.edu>
#=========================================
# Set parameters
#=========================================
if [[ $# < 2 ]]
then
echo "illegal number of parameters"
exit 1
fi
DREAL_BIN=$1
if [ ! -f ${DREAL_BIN} ]
then
echo "${DREAL_BIN} does not exist."
exit 1
fi
SMT_FILE=$2
if [ ! -f ${SMT_FILE} ]
then
echo "${SMT_FILE} does not exist."
exit 1
fi
shift; shift;
OPTIONS=$@
EXIT_CODE=1
#=========================================
# Run dReal
#=========================================
RESULT_FILE=`mktemp /tmp/dReal.out.XXXXXX` || exit 1
echo "Running: ${DREAL_BIN} $OPTIONS ${SMT_FILE}"
${DREAL_BIN} $OPTIONS ${SMT_FILE} > ${RESULT_FILE} || exit 1
#=========================================
# Check sat/unsat and return exit_code
#=========================================
tail -n 1 ${RESULT_FILE} | grep "^sat" && EXIT_CODE=51
tail -n 1 ${RESULT_FILE} | grep "^unsat" && EXIT_CODE=52
rm ${RESULT_FILE}
exit ${EXIT_CODE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment