#!/bin/sh
# $Id: run 1958 2008-01-07 20:03:44Z eldering $

# Run wrapper-script for 'test_solution.sh'.
# See that script for more info.

# Usage: $0 <program> <testin> <output> <error> <exitfile>
#
# <program>   Executable of the program to be run.
# <testin>    File containing test-input.
# <output>    File where to write solution output.
# <error>     File where to write error messages.
# <exitfile>  File where to write solution exitcode.

PROGRAM="$1";   shift
TESTIN="$1";    shift
OUTPUT="$1";    shift
ERROR="$1";     shift
EXITFILE="$1";  shift

# Run the program while redirecting input, output and stderr
$PROGRAM <$TESTIN >$OUTPUT 2>$ERROR
exitcode=$?

printf "$exitcode" >$EXITFILE

exit $exitcode
