aboutsummaryrefslogtreecommitdiff
path: root/Bin
diff options
context:
space:
mode:
authorIan Hinder <ian.hinder@aei.mpg.de>2013-04-14 20:29:45 +0200
committerIan Hinder <ian.hinder@aei.mpg.de>2013-04-14 20:29:45 +0200
commit519f2cd182c4828e74429e883139fbb8b1a11d3c (patch)
tree461d4c2c68e7d0bbbca60263d159ee267e207759 /Bin
parent46540ff11edf9b5b6b0df44a9df2790e0a48eb7a (diff)
kranc: Don't rely on Mathematica exit code for detecting failure
When no licence is available, Mathematica still exits with a zero exit code. This causes dependency-based systems such as Make to assume that the thorn was created successfully, when it might not have been. To work around this, we perform a file operation (deleting a temporary directory) from within Mathematica, and check that this was successful after Mathematica finishes, and adjust the exit code of the script accordingly. Fixes Issue #39.
Diffstat (limited to 'Bin')
-rwxr-xr-xBin/kranc25
1 files changed, 24 insertions, 1 deletions
diff --git a/Bin/kranc b/Bin/kranc
index e82e75a..dafc76c 100755
--- a/Bin/kranc
+++ b/Bin/kranc
@@ -48,4 +48,27 @@ else
exit 1
fi
-$MATH -run "Get[\"$KRANCDIR/Tools/MathematicaMisc/RunKranc.m\"]" $MMASCRIPT </dev/null
+# If there is no licence server, Mathematica still exits with a 0 exit
+# code. In order to catch this error and exit with a nonzero code, we
+# first create a temporary directory, then remove it from within
+# Mathematica, then check to see that this happened. If it didn't, we
+# assume there was some problem with launching Mathematica.
+
+flagdir="kranc.tmp.$$" # mktemp is not the same on Linux and Mac OS; here we assume we can write to the current directory
+mkdir $flagdir
+
+if $MATH -run "DeleteDirectory[\"$flagdir\"]; Get[\"$KRANCDIR/Tools/MathematicaMisc/RunKranc.m\"]" $MMASCRIPT </dev/null; then
+ if [ ! -d "$flagdir" ]; then
+ # Mathematica kernel started and executed DeleteDirectory
+ exit 0
+ else
+ echo "Mathematica did not start successfully"
+ rmdir "$flagdir"
+ exit 1
+ fi
+else
+ if [ -d "$flagdir" ]; then
+ rmdir "$flagdir"
+ exit 1
+ fi
+fi