A execução de amostra para argumentos TEST1 TEST2 TEST3 deve ser
TEST1 (from outer loop)
TEST1 (from inner loop)
TEST2 (from outer loop)
TEST1 (from inner loop)
TEST2 (from inner loop)
TEST3 (from outer loop)
TEST1 (from inner loop)
TEST2 (from inner loop)
TEST3 (from inner loop)
Use o seguinte arquivo de lote (test.cmd):
@echo off
setlocal
setlocal EnableDelayedExpansion
set /a _count=0
for %%a in (%*) do (
echo %%a ^(from outer loop^)
set /a _count=!_count!+1
set /a _stop=0
call :InnerLoop %*
)
goto :eof
:InnerLoop
for %%b IN (%*) do (
set /a _stop=!_stop!+1
echo %%b ^(from inner loop^)
if [!_stop!]==[!_count!] goto :next
)
:next
goto :eof
endlocal
Exemplo de saída:
F:\test>test TEST1 TEST2 TEST3
TEST1 (from outer loop)
TEST1 (from inner loop)
TEST2 (from outer loop)
TEST1 (from inner loop)
TEST2 (from inner loop)
TEST3 (from outer loop)
TEST1 (from inner loop)
TEST2 (from inner loop)
TEST3 (from inner loop)
Leitura Adicional
- Um índice A-Z da linha de comando do Windows CMD - Uma excelente referência para todas as coisas relacionadas à linha do Windows cmd.