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
How to define "global" variables? Valid also for :proc?
Moderator: DosItHelp
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: How to define "global" variables? Valid also for :proc?

It seems to work fine. But also, try using !pathtoxxx!\program.exe !flag! "!file!" in :proc instead.
Re: How to define "global" variables? Valid also for :proc?
I assume there is an endlocal in the original (non simplified) batch program between the for loop and the ":proc" label (but this is not needed).
In addition there is missing a "goto :eof" /"exit [/b [n]]" instruction as in the simplified batch program,
so the procedure ":proc" is executed without calling it.
The last behavior can be seen on the Command Prompt window of ShadowThief:
The doubled "C:\Windows 55 "two"" line.
penpen
In addition there is missing a "goto :eof" /"exit [/b [n]]" instruction as in the simplified batch program,
so the procedure ":proc" is executed without calling it.
The last behavior can be seen on the Command Prompt window of ShadowThief:
The doubled "C:\Windows 55 "two"" line.
penpen