can't change startup directory when calling matlab with -automation from command line
Mostra commenti meno recenti
Windows 7, Matlab 2007b.
I want to call Matlab to run a script from a windows 7 .bat file. I'm using the command:
matlab -automation -r myScript
The problem is that the script needs to access some files in (or relative to) the directory where the bat file is located. In theory this shouldn't be a problem since the startup directory should be the same directory as the bat file, from Matlab help:
"When you do not specify the -sd option, the startup directory is the directory from which you ran matlab"
But in practice the startup directory is the Matlab root directory: C:\Program Files\MATLAB\R2007b
I tried also explicitly setting the startup directory using:
matlab -automation -sd "%CD%" -r myScript
but the startup directory is still Matlab root.
The problem only happens with the -automation flag, if I leave that out then it works fine - but if I leave that out then Matlab takes much longer to start and it slows down my whole process.
2 Commenti
Robert Wilson
il 9 Gen 2013
Andrew Lee
il 24 Giu 2014
I'm experiencing the same problem in R2012b. In my case I need to utilize Java classes so the -nojvm flag isn't an option. Also, I can't use the post-launch 'cd' approach because I'm using a custom classpath.txt file in the launch directory (which doesn't get picked up when using the -automation flag).
Risposte (1)
Try
set CHANGE_DIR_CMD=cd('%CD%')
matlab -automation -r "%CHANGE_DIR_CMD%;myScript"
Categorie
Scopri di più su Startup and Shutdown 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!