I just had something completely bizarre come up, and I was wondering if this was expected behavior or if I've found some sort of strange bug in batch file processing. Without going into the details of what I'm trying to do, below is an example script that shows the behavior I'm talking about.
More or less, what I'm experiencing is that global environment variables that are set inside of a function call that is called from inside a if statement don't actually get set until the if statement exits!
@echo off
set myvar=1
echo %myvar% (should be 1)
if [%fakevar%] == [] (
call:setEnvVars
echo %myvar% (should be 2^)
)
echo %myvar% (should be 2)
:setEnvVars
set myvar=2
GOTO:EOF
The output is as follows:
1 (should be 1)
1 (should be 2)
2 (should be 2)
So, to reiterate, is this expected behavior (and why)? Or have I run into some sort of bug?