Solved Why does my for loop only execute once?

October 10, 2018 at 06:24:25
Specs: Windows 10
Hi guys,
Why does this batch file only execute the first command in the for loop?
I don’t get any errors when running the commands independently.


@echo off
set filename=BRAWL-OFF
set team=(members.txt)

set effect=""

set gauntlet= Mesmerize Mutant-7
set invpath=data/ownedcards/ownedcards_
set i1=100
set i2=100
set i3=0.001
set threads=30

set youroff=""
set oppdef=""

set flags=dom+ -L 9 10 +uc


@echo on

FOR /F %%m IN %team% DO (


tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% anneal %i1% %i2% %i3%|find "Optimized Deck" >>%filename%.txt
tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% fund 15000 anneal %i1% %i2% %i3% |grep -E "Optimized Deck|Upgraded Cards" >>%filename%.txt
)



See More: Why does my for loop only execute once?

Reply ↓  Report •

✔ Best Answer
October 10, 2018 at 08:11:16
I'll do a workaround as i do not see the problem... <3 batch

@echo off&setlocal enabledelayedexpansion
set filename=BRAWL-OFF
set team=members.txt
if not exist "%team%" (echo ERROR: There is no %team% in the current cmd working directory: %CD%&pause>nul&exit/b)
set effect=""
set gauntlet=" Mesmerize Mutant-7"
set invpath=data/ownedcards/ownedcards_
set i1=100
set i2=100
set i3=0.001
set threads=30
set youroff=""
set oppdef=""
set "flags=dom+ -L 9 10 +uc"
echo off>%filename%.txt
FOR /F "tokens=1 delims= " %%m IN ('type "%team%"') DO (
call :command1 %%m
call :command2 %%m
)
echo results:
type %filename%.txt
pause>nul
exit/b
:command1
tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! anneal %i1% %i2% %i3% | find "Optimized Deck" >>%filename%.txt
exit/b
:command2
tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! fund 15000 anneal %i1% %i2% %i3% | grep -E "Optimized Deck | Upgraded Cards" >>%filename%.txt
exit/b

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz



#1
October 10, 2018 at 06:28:35
One more question:
Can I prepend the %%m variable to the output of Upgraded Cards?
grep -E "Optimized Deck|Upgraded Cards" >>%filename%.txt

Reply ↓  Report •

#2
October 10, 2018 at 07:07:09
try this first, i only did minor changes:

@echo off
set filename=BRAWL-OFF
set team=members.txt
set effect=""
set "gauntlet= Mesmerize Mutant-7"
set invpath=data/ownedcards/ownedcards_
set i1=100
set i2=100
set i3=0.001
set threads=30
set youroff=""
set oppdef=""
set "flags=dom+ -L 9 10 +uc"
FOR /F %%m IN (%team%) DO (
tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% anneal %i1% %i2% %i3% | find "Optimized Deck" >>%filename%.txt
tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% fund 15000 anneal %i1% %i2% %i3% | grep -E "Optimized Deck | Upgraded Cards" >>%filename%.txt
)
echo results:
type %filename%.txt


random tip:

also if you want to cleanup BRAWL-OFF.txt before the loop, as in make it empty before you start piping the output of tuo.exe into BRAWL-OFF.txt, use this command and place it below this line:
"set "flags=dom+ -L 9 10 +uc"":

echo off>%filename%.txt

random tip 2:

batch doesnt like the character:
|
You can try changing it to:
^|
and see what happens.

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz


Reply ↓  Report •

#3
October 10, 2018 at 07:27:00
Hi,
Thanks for responding, I’ve changed the script to this:

@echo off
set filename=BRAWL-OFF
set team=members.txt
set effect=""
set "gauntlet= Mesmerize Mutant-7"
set invpath=data/ownedcards/ownedcards_
set i1=100
set i2=100
set i3=0.001
set threads=30
set youroff=""
set oppdef=""
set "flags=dom+ -L 9 10 +uc"

echo off>%filename%.txt
FOR /F %%m IN (%team%) DO (
tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% anneal %i1% %i2% %i3% | find "Optimized Deck" >>%filename%.txt
pause
tuo.exe "%%m" "%gauntlet%" pvp ordered -t %threads% endgame 1 -o=%invpath%%%m.txt yf %youroff% ef %oppdef% -e %effect% _startdecks %flags% fund 15000 anneal %i1% %i2% %i3% | grep -E "Optimized Deck | Upgraded Cards" >>%filename%.txt
pause
)
echo results:
type %filename%.txt


I like the “echo off>%filename%.txt” suggestion, that works very well but the script did not like “^|”.
Unfortunately, it still only runs until the first pause then it exits the script completely


Reply ↓  Report •

Related Solutions

#4
October 10, 2018 at 07:32:41
Could you tell me what is written in members.txt?

like give me the first 5 lines for example

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz

message edited by hidde663


Reply ↓  Report •

#5
October 10, 2018 at 07:53:55
yes of course, members.txt contains:

Amalphy
Anthonydread75
BloodKi1
Bloodynin3


Reply ↓  Report •

#6
October 10, 2018 at 08:11:16
✔ Best Answer
I'll do a workaround as i do not see the problem... <3 batch

@echo off&setlocal enabledelayedexpansion
set filename=BRAWL-OFF
set team=members.txt
if not exist "%team%" (echo ERROR: There is no %team% in the current cmd working directory: %CD%&pause>nul&exit/b)
set effect=""
set gauntlet=" Mesmerize Mutant-7"
set invpath=data/ownedcards/ownedcards_
set i1=100
set i2=100
set i3=0.001
set threads=30
set youroff=""
set oppdef=""
set "flags=dom+ -L 9 10 +uc"
echo off>%filename%.txt
FOR /F "tokens=1 delims= " %%m IN ('type "%team%"') DO (
call :command1 %%m
call :command2 %%m
)
echo results:
type %filename%.txt
pause>nul
exit/b
:command1
tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! anneal %i1% %i2% %i3% | find "Optimized Deck" >>%filename%.txt
exit/b
:command2
tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! fund 15000 anneal %i1% %i2% %i3% | grep -E "Optimized Deck | Upgraded Cards" >>%filename%.txt
exit/b

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz


Reply ↓  Report •

#7
October 10, 2018 at 08:47:00
thats cracked it, thanks

One more question:
Can I prepend the %1 variable to the output of Optimized Deck and Upgraded Cards?
grep -E "Optimized Deck|Upgraded Cards" >>%filename%.txt

so i would get something like this:
Amalphy Optimized Deck .....
Amalphy Upgraded Cards .....


Reply ↓  Report •

#8
October 10, 2018 at 09:57:14
Replace the 2 command labels with:

:command1
for /f "tokens=*" %%a in ('tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! anneal %i1% %i2% %i3% | find "Optimized Deck"') do (echo %1 Optimized Deck - %a >>%filename%.txt)
exit/b
:command2
for /f "tokens=*" %%a in ('tuo.exe "%1" !gauntlet! pvp ordered -t !threads! endgame 1 -o=!invpath!%1.txt yf !youroff! ef !oppdef! -e !effect! _startdecks !flags! fund 15000 anneal %i1% %i2% %i3% | grep -E "Optimized Deck | Upgraded Cards"') do (echo %1 Upgraded Cards - %a >>%filename%.txt)
exit/b

There are a few other ways to do it, but i don't feel like trying those :D

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz


Reply ↓  Report •

#9
October 10, 2018 at 09:59:10
Thank you very much!

Reply ↓  Report •

Ask Question