I want to determine what the PATH environment variable was after I execute a batch file (vcvarsall.bat) by running
cmd /c "vcvarsall.bat x86_amd64 && echo %PATH%"
but what happens is not what I expect. For example, if I run:
cmd /c "set PATH=test && echo %PATH%"
I just get the PATH of the host process, not “test” as I expected, as echo %PATH% should be running in the context of the child process, not the parent. So, why does this happen, and how do I go about getting the result I’m after?
will interpret
PATHbefore it’s changed. This is actually a neat trick to export environment variables outside of asetlocal/endlocalchunk with:Normally (without the
&& xyzzy=...bit, thexyzzyvariable would still be the initial value of twisty after the block but the fact that the%xyzzy%is interpreted before the entireendlocalline while thesetis actioned after theendlocalcommand, allows you to export the change.If you want to interpret a variable after the
set, you need delayed expansion:The
/v:onturns on delayed expansion and the use of!instead of%indicates that you want to use that delayed expansion.