MATLAB: Does only one line in the batch file get executed when working with MATLAB 7.4 (R2007a)

MATLAB

I have a batch file that runs a MATLAB program, then echos some text in the command prompt and then runs a second program in a new process. My batch file looks like as follows:
matlab -nosplash -nodesktop -r "cd C:\Temp;test1;quit" -logfile C:\Temp\logfile1.txt
echo This is a test
matlab -nosplash -nodesktop -wait -r "cd C:\Temp;test2;quit" -logfile C:\Temp\logfile2.txt
When I execute the batch file in the command prompt, only the first command is executed. I do not see the echo message and the second program does not get executed.

Best Answer

To work around this issue, you will need to modify the environment variable PATH on your machine.
The path to "$MATLABROOT\bin\win32" needs to be moved to the left of the path to "$MATLABROOT\bin". Note that $MATLABROOT denotes the full MATLAB installation path. For example, if your current configuration currently looks as follows:
C:\Windows;C:\Windows\System32\;... etc. ...;C:\MATLAB\R2007a\bin;C:\MATLAB\R2007a\bin\win32;... etc. ...
You will need to modify it so that it looks as follows:
C:\Windows;C:\Windows\System32\;... etc. ...;C:\MATLAB\R2007a\bin\win32;C:\MATLAB\R2007a\bin;... etc. ...
After changing the environment variable, you need to close and reopen the command prompt window for the change to take effect.
The environment variable PATH gets interpreted from left to right, so this change will cause the file "bin\win32\matlab.exe" to be executed instead of "bin\matlab.exe". This behavior was corrected in MATLAB 7.5 (R2007b), so this manual change of the environment variable is no longer needed in newer releases of MATLAB.