Call Matlab script via command line
Mostra commenti meno recenti
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 Commenti
Rik
il 10 Set 2019
If you don't get an actual answer, you could write errors to a text file and read the contents in the windows command line.
N/A
il 10 Set 2019
Rik
il 10 Set 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.
Risposte (1)
Lexi Crommett
il 9 Apr 2021
0 voti
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
Categorie
Scopri di più su C Shared Library Integration in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!