MATLAB: Running scripts from command line

command line

I'm trying to use matlab script as one of the build steps in my program. I'm doing it like this:
matlab.exe -r "cd c:\outdir, run ('c:\outdir\my.m'), quit"
It works just fine, but if the script fails on some reason, matlab doesn't close with error code. It just hangs waiting for input, showing me the line when error happens. This blocks my build, because it waits for matlab to close.
Is there any way to quit after script failed? Or may be there's another way to run the script, so that it returns back to command line in any case?

Best Answer

if you don't need error information, you could just enclose your call to run() in a try/end, such as:
matlab.exe -r "cd c:\outdir; try, run ('c:\outdir\my.m'); end; quit"