How to get a return value(or exit code) from matlab

12 ビュー (過去 30 日間)
Cormier
Cormier 2018 年 7 月 23 日
編集済み: Jan 2018 年 7 月 23 日
I'm trying to retrieve some value from my matlab script just so I can let the system know whether the program worked successfully or not. I'm running the matlab script from the window command line. Also, I wanna send the value through the whole pipeline. Do you have any good idea? Thank you so much in advance.
  1 件のコメント
Jan
Jan 2018 年 7 月 23 日
編集済み: Jan 2018 年 7 月 23 日
What exactly is "the whole pipeline"? If you post the command, adjusting it is much easier.

サインインしてコメントする。

採用された回答

Jan
Jan 2018 年 7 月 23 日
編集済み: Jan 2018 年 7 月 23 日
What about writing a file inside Matlab and using its contents from the Windows Command prompt?
Use a function instead of a script for flexibility.
function yourFunction(OutFile)
... do what ever you want
fid = fopen(OutFile, 'w');
if fid == -1
error('Cannot open output file') % Bad bad bad - you cannot see this in the caller!
end
fprintf(fidm 'success\n');
fclose(fid);
end
The run in Windows' command prompt:
matlab -r "yourFunction('C:\Temp\Output.log')"
Now e.g.
set /p Build=<C:\Temp\Output.log
can catch the output.
Another option is to start Matlab with an output file and parse this later:
matlab -wait -logfile output.log

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by