How to quit MATLAB if syntax error in command line code (option -r)

Viewed 144

I need to run MATLAB in batch mode and would like to catch all possible errors. The following code

matlab -nojvm -nodesktop -nosplash -r "try, x=y; catch ME, disp(getReport(ME)); end; exit"

works fine and MATLAB correctly complains

Undefined function or variable 'y'.

However, for syntax errors such as this

matlab -nojvm -nodesktop -nosplash -r "try, x:=y; catch ME, disp(getReport(ME)); end; exit"

MATLAB says

 try, x:=y; catch ME, disp(getReport(ME)); end; exit
        |
Error: Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.
>> 

and pauses at the command prompt. A brute force method to prevent this behavior is

echo "exit" | matlab -nojvm -nodesktop -nosplash -r "try, x:=y; catch ME, disp(getReport(ME)); end; exit"

Is there a more elegant way to solve this issue? Thanks.

MATLAB Version: 9.5 (R2018b), OS: Linux 4.12.14 (OpenSUSE)

0 Answers
Related