Call Matlab script via command line

21 次查看(过去 30 天)
N/A
N/A 2019-9-10
We try to call a Matlab script via MS-DOS command line:
"D:\Install_Matlab\bin\matlab.exe" -nodisplay -nodesktop -r "run('D:\test.m');exit;"
We added some extra options (like -nodesktop) in the command because we want to run this command in batch (so without any user interaction). With the above command we can successfully run our script ("test.m"). However, the problem is that we don't get any error message if the script fails. What do we have to change in our command so that we can retrieve the error(s)?
  3 个评论
N/A
N/A 2019-9-10
Ok, so if you return an error in the Matlab script (or there is a technical error, for example a syntax error) the command will not automatically give a returncode different from 0?
(with compiled Matlab code we just check the RC of the MS-DOS command)
Rik
Rik 2019-9-10
I would strongly suggest you make sure the code can run in the first place, before running it headless. Then you can wrap the whole thing in a try-catch and write any error to a text file. The return code might be set with your current setup, but I have very little experience with this level of detail in running Matlab headless, so I don't know what settings are available.

请先登录,再进行评论。

回答(1 个)

Lexi Crommett
Lexi Crommett 2021-4-9
You can use the -logfile "logfilename" startup option to write any output from MATLAB to a log file. This should allow you to see any errors by looking at that log file.
Your command would then look like this:
"D:\Install_Matlab\bin\matlab.exe" -nodisplay -nodesktop -logfile "D:\myLog.txt" -r "run('D:\test.m');exit;" (assuming that D is the directory where you want the log file)

类别

Help CenterFile Exchange 中查找有关 C Shared Library Integration 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by