Windows batch goto inside FOR loop
batch-file, for-loop, goto, windows
Solution
Try
for /f "skip=1 tokens=1,2,3,4,5,6,* delims=;" %%a in ('findstr /R "^" z:\csp\levantamento\levantamentoNOVO.csv') do (
set /A HOME=0
call :cicle "%%a" "%%c"
)
:: what-to-do-after-for goes in here
goto :eof
:cicle
echo HOME%HOME%
echo \\%~2\HKLM\SOFTWARE\ORACLE\HOME%HOME%
reg query \\%~2\HKLM\SOFTWARE\ORACLE\HOME%HOME% /v ORACLE_HOME
if %HOME% leq 3 (
set /A HOME+=1
goto cicle
)
echo.
echo Connection to %~1 deleted
goto :eof
Note that now there is a subroutine called `cicle` which is supplied with parameters `"%%a"` and `"%%c"` Within the `cicle` routine, what was `%%a` becomes `%~1` (the first parameter, minus the quotes) and what was `%%c` becomes `%~2` (the second parameter, minus the quotes).
The quotes are only there in case the parameter being passed contains separator characters, which is unlikely in your current case.
see `call /?` from the prompt for docco.
Note also that `set "var=variable"` is used in string assignments to ensure unwanted trailing spaces are not included in the value assigned. The `set /a` syntax does not suffer from this problem, so the rabbit's ears are not necessary.
Problem
I have a Windows batch file to read a file, get some info from it, like machine IP, and then print some registry values for that machine, something like this: ``` for /f "skip=1 tokens=1,2,3,4,5,6,* delims=;" %%a in ('findstr /R "^" z:\csp\levantamento\levantamentoNOVO.csv') do ( set /A "HOME=0" :cicle echo HOME%HOME% echo \\%%c\HKLM\SOFTWARE\ORACLE\HOME%HOME% reg query \\%%c\HKLM\SOFTWARE\ORACLE\HOME%HOME% /v ORACLE_HOME if %HOME% leq 3 ( set /A "HOME+=1" goto cicle ) else ( echo. ) echo Conenction to %%a deleted ) ``` and my output is this: ``` HOME0 \\10.13.3.27\HKLM\SOFTWARE\ORACLE\HOME0 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0 ORACLE_HOME REG_EXPAND_SZ d:\oracle\806 HOME1 \\%c\HKLM\SOFTWARE\ORACLE\HOME1 ERROR: The network path was not found. HOME2 \\%c\HKLM\SOFTWARE\ORACLE\HOME2 ERROR: The network path was not found. HOME3 \\%c\HKLM\SOFTWARE\ORACLE\HOME3 ERROR: The network path was not found. HOME4 \\%c\HKLM\SOFTWARE\ORACLE\HOME4 ERROR: The network path was not found. Conenction to %a deleted ``` When I do a goto cicle, it appear that the FOR loop doesn't know anymore hat the %%c and %%c are. I really don't know what I'm doing wrong.