I'm running the Mathematica kernel math from inside a makefile to generate C++ code, like so:
a.out:
g++ -o a.out main.cpp
main.cpp:
math -run "<< \"generate_main.m\"" # generates main.cpp
However, sometimes there is no Mathematica license available on the machine where make is called (license has expired, connection to license server has been lost, ...). In such a case, the Mathematica kernel does not quit, but instead waits for the user to input a license password. So, make will never finish. In such a case, I'd like math to quit with a non-zero exit code. How can this be achieved?
Most convenient would be a command line option for the Mathematica kernel, like -quit-if-no-license. math -quit-if-no-license could then for example also be used in a configure script to check if the Mathematica kernel can be run.
$BatchInputto move out of batch mode. – TimRias Oct 13 '17 at 07:50stdinis closed afterecho "2+2"has finished. Ifstdinis closed and the correct license password has not been entered, Mathematica returns with the exit code1. This non-zero exit code can be checked for. – Alexander Voigt Oct 16 '17 at 17:55