Bat, How to Prevent Environment Variables Leaking into Parent Process
I Have a Bat File Similiar to This Rem Build. Bat Rem Add Visual Studio Paths to Env Call "%Programfiles(X86)%\Microsoft Visual Studio\2019\Community\Vc\Auxilia...
I have a bat file similiar to this
rem build.bat
rem add visual studio paths to env
call "%PROGRAMFILES(X86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
cl.exe blabla
After running it a couple of times I get the error The input line is too long. because vcvarsall.bat seems to append to the path variables every time I invoke the script
I invoke the script with build.bat
I thought that the environment variables should not be saved between runs. Is there any way to make the variables not leak into the calling cmd shell?
3 Answers
You could start the build.bat in a child process.
cmd /c build.bat
Variables in the parent process aren't affected by a child process.
As far as I understand, environment variables don't get saved between runs, which is correct, but a "run" in this case is not the "run" of the batchfile, but of the command prompt in which you run the batchfile.
In my opinion, you have opened a command prompt. In there you launch the "build.bat" file, over and over again.
However, if you would launch the batchfile from outside of a command prompt (like double-clicking from the Windows explorer), this problem should not appear.