Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file: for loop running twice

I'm trying to write a batch which extracts a value of a parameter from an ini file. The problem is that this for loops iterates twice:

call:ini DW_LOADER_FeedsRootDir UDM_Folder
:ini
for /f "tokens=2 delims==" %%U in ('find "%~1=" DW_environmentConfig.ini') do (
 set %~2=%%U
)

the batch does not end after this line, and all the commands that follow it are also repeated twice. I can't use a command like 'goto:eof' after the loop. Does anyone has an idea as to why this happens?

like image 958
user3240866 Avatar asked Jul 12 '26 12:07

user3240866


1 Answers

When you use CALL:INI the batch calls your function, and when it ends, it returns to CALL command point, then it goes to :ini label again.

Try it:

call:ini DW_LOADER_FeedsRootDir UDM_Folder
goto:eof
:ini
for /f "tokens=2 delims==" %%U in ('find "%~1=" DW_environmentConfig.ini') do (set %~2=%%U)
like image 106
Rafael Avatar answered Jul 14 '26 11:07

Rafael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!