0

I have this build file:

@echo off
call "%VS120COMNTOOLS%"\\vsvars32.bat
echo Deleting old exe...
del build_win32\dist\bin\OgreApp_d.exe
cd build_win32
echo Building As Debug
msbuild /detailedsummary /p:Configuration=Debug /p:Platform=x86 /t:build ALL_BUILD.vcxproj
echo Done building, Exiting.
cd dist\bin\
start OgreApp_d.exe
cd ../../../

And to run it I run from cmd build. The problem is that since I do not exit cmd between builds, the PATH grows and grows because of "%VS120COMNTOOLS%"\\vsvars32.bat until it refuses to run because path is too long. Is there a way I can start this in another shell but in the same place.

I could do

start cmd.exe /K "build.bat"

but it opens a new window and it is more complicated than just build

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vinz243
  • 9,654
  • 10
  • 42
  • 86

1 Answers1

1

The advice of Bill_Stewart is very good and very easy to apply:

@echo off
setlocal
call "%VS120COMNTOOLS%"\\vsvars32.bat
echo Deleting old exe...
del build_win32\dist\bin\OgreApp_d.exe
cd build_win32
echo Building As Debug
msbuild /detailedsummary /p:Configuration=Debug /p:Platform=x86 /t:build ALL_BUILD.vcxproj
echo Done building, Exiting.
cd dist\bin\
start OgreApp_d.exe
cd ../../../
endlocal

A new local copy of the environment variables table is made with command setlocal. All changes on environment variables are done now on this local copy instead of the environment variables of always running command line interpreter process. The temporary local table of the environment variables is deleted by command endlocal. So value of PATH is not growing and growing on every execution of this batch file.

By the way: vsvars32.bat is obviously coded poorly as it does not check on current PATH if a folder path to add is not already included in PATH. My answer on Why are other folder paths also added to system PATH with SetX and not only the specified folder path? contains the few code lines to check PATH for a folder path to add before appending it to PATH.

Mofi
  • 46,139
  • 17
  • 80
  • 143