Running scripts from command line

조회 수: 111 (최근 30일)
Other
Other 2011년 5월 27일
편집: Sourabh Kondapaka 2020년 9월 22일
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?

채택된 답변

Ben Mitch
Ben Mitch 2011년 5월 27일
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
Tommaso Seresini
Tommaso Seresini 2020년 1월 31일
could you elaborate on what the "end" is for? i tried running it without the "try" (catches errors ) and the "quit"( which closes matlab) but i obtain an error:
Error: Illegal use of reserved keyword "end".
Thanks
Sourabh Kondapaka
Sourabh Kondapaka 2020년 9월 22일
편집: Sourabh Kondapaka 2020년 9월 22일
Hi @Tommasso,
the "end" is for the "try" block. If you are going to remove "try" keyword, you'll also have to remove "end"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by