Call Matlab script via command line
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 10 Sep. 2019
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.
Antworten (1)
Lexi Crommett
am 9 Apr. 2021
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)
Here's a link to some commonly used startup options: https://www.mathworks.com/help/matlab/matlab_env/commonly-used-startup-options.html
0 Kommentare
Siehe auch
Kategorien
Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!