Setting variables and taking effect in one batch command line -
i found out if following:
set variable=test & echo %variable% --outputs "%variable%" echo %variable% --outputs "test" the change won't take effect until new line runs. need have take effect need use long, one-lined command.
you need delayed expansion or call echo:
@echo off setlocal enabledelayedexpansion set var=val&echo !var! endlocal set var=val&call echo %%var%% if have compositions of commands put & or in brackets set command take effect after of them executed.so need or delayed expansion (which allow access variables ! instead of %) or call
to enable delayed expansion in command prompt need start cmd /v:on :
>cmd /v:on >set variable=test & echo !variable!
Comments
Post a Comment