How to define "global" variables? Valid also for :proc?
Posted: 06 Jun 2014 22:25
Assume I have a (simplified) DOS batch procedure like the one shown at the bottom.
Much to my surprise I have to redefine/set the two variables pathtoxxx and flag in the calling AND in the called procedure.
When I omit the second redefinition in the :proc the script won't run.
Is there really no other way to define variables globally?
Peter
@echo off &setlocal DisableDelayedExpansion
setlocal EnableDelayedExpansion
set pathtoxxx=D:\tmp\xxx
set flag=55
for %%i in (!params!) do (
echo processing %pathtoxxx% and %flag%
set "file=%%~i"
call :proc
)
:proc
set pathtoxxx=D:\tmp\xxx
set flag=55
%pathtoxxx%\program.exe %flag% "%file%"
goto :eof
Much to my surprise I have to redefine/set the two variables pathtoxxx and flag in the calling AND in the called procedure.
When I omit the second redefinition in the :proc the script won't run.
Is there really no other way to define variables globally?
Peter
@echo off &setlocal DisableDelayedExpansion
setlocal EnableDelayedExpansion
set pathtoxxx=D:\tmp\xxx
set flag=55
for %%i in (!params!) do (
echo processing %pathtoxxx% and %flag%
set "file=%%~i"
call :proc
)
:proc
set pathtoxxx=D:\tmp\xxx
set flag=55
%pathtoxxx%\program.exe %flag% "%file%"
goto :eof