I digged out that variable is empty if you are using conditions and set in conditions!
if errorlevel 0 (
Set localVar="fooBar"
echo "%localVar%"
)
will result in an empty output!
related to string comparison in batch file
use
SetLocal EnableDelayedExpansion
to enable !VARNAME!
that will enable to use !VARNAME!
in a condition beneath but will still not enable output for %VARNAME%
in the conditional block!
Use Set BEFORE the condition to get it accessible in the conditional block.
OR usage must be AFTER conditional block where Set was used in.
(!) Currently I don't know how to challenge Set AND usage in the same block!
See some example code in https://gist.github.com/childnode/0f6c874ad79788a86332
(!) But as you can see in the results (also in gist) using DelayedExpansion has a different side effect:
Variable is set on second run in same shell (what is obviously correct) but for some reasons are not set with EnableDelayedExpansion
in second run (seems to it also cleans up "local" variables from script and doesn't export it for following commands!
This might cause other error if different batch files are run in "pipe"