can't change startup directory when calling matlab with -automation from command line

10 Ansichten (letzte 30 Tage)
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 Kommentare
Robert Wilson
Robert Wilson am 9 Jan. 2013
Update: I've changed my command to
matlab -nojvm -nosplash -r myScript
which is working. The downside is the with no java there's no editor and I can't debug in realtime, but it's an acceptable work around for now.
Andrew Lee
Andrew Lee am 24 Jun. 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).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

TAB
TAB am 10 Jan. 2013
Bearbeitet: TAB am 10 Jan. 2013
Try
set CHANGE_DIR_CMD=cd('%CD%')
matlab -automation -r "%CHANGE_DIR_CMD%;myScript"

Kategorien

Mehr zu Startup and Shutdown 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!

Translated by