Running scripts from 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?

 採用された回答

Ben Mitch
Ben Mitch 2011 年 5 月 27 日

5 投票

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 件のコメント

Other
Other 2011 年 5 月 27 日
Great! It works.
Richard
Richard 2017 年 10 月 9 日
What if you want to pass arguments?
David King
David King 2018 年 12 月 20 日
I need the error information.
It seems the try/catch solution above discards any errors that occur.
Is there a way for matlab to exit and also obtain any errors/warning info from the command line?
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 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2011 年 5 月 27 日

編集済み:

2020 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by