MATLAB: Perform Visual Studio Build from MATLAB command prompt

matlab command for executing devenv

Hi,
I want to build Visual Studio project from MATLAB, using devenv command. I can do the build from dos command prompt, but not from MATLAB command prompt
For example I tried
system('Set PATH=C:/Program Files/Microsoft Visual Studio 9.0/Common7/IDE;%PATH%');
[status result]= system('devenv example.sln /Rebuild "Debug -example|Win32"')
I also tried addpath command to set the path and used dos command instead of system, yet it did not work.
But If I put this command in batch file (.bat) call the batch file using system or dos command it works.
Any Clue why devenv command does not work from MATLAB command prompt.
Regards
MOS

Best Answer

Try putting "&&" between your commands and make them one. For example,
system('set path=... && devenv...')
Alternatively, calling the batch file will also work.
The reason this is happening has already been stated -- when you open a system() window, it sources a new shell that inherits the default environment. Subsequent shells get a new environment.
Related Question