Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Muliple DO command before going to the next line in txt file for Batch For /F

Tags:

batch-file

I have this code in .bat file

FOR /F "tokens=* delims= " %%G in (partners.txt) DO "C:\Program Files (x86)\iOpus\iMacros\iMacros.exe" -macro "screenshot.iim" -var_offercode %%G
ANOTHER COMMAND

How can I instruct the batch file to do the ANOTHER COMMAND first before getting the next input for variable %GG from partners.txt. basically, I need to complete the first cycle first before going on the next line. Currently, it finishes the list in partners.txt before moving to ANOTHER COMMAND.

Thanks a lot!

like image 621
liza Avatar asked Nov 29 '25 16:11

liza


1 Answers

Put a statement list in parentheses:

for /f %%x in (partners.txt) do (
  statement 1
  statement 2
)

One thing to note before you ask one of the most frequent questions as a follow-up one: Environment variables are expanded for the whole block as soon as the line is parsed which means if you set environment variables somewhere in that block the changes will not be visible until you step out of the loop. See help set for a discussion of the problem and a solution. If you need to go that route, that is.

like image 96
Joey Avatar answered Dec 01 '25 16:12

Joey



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!