Running scripts from command line

565 views (last 30 days)
Other
Other on 27 May 2011
Edited: Sourabh Kondapaka on 22 Sep 2020
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?

Accepted Answer

Ben Mitch
Ben Mitch on 27 May 2011
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"
  5 Comments
Sourabh Kondapaka
Sourabh Kondapaka on 22 Sep 2020
Hi @Tommasso,
the "end" is for the "try" block. If you are going to remove "try" keyword, you'll also have to remove "end"

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!