Nested For /F in batch reading input from txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lizac
Posts: 3
Joined: 07 Apr 2011 02:08

Nested For /F in batch reading input from txt

#1 Post by lizac » 07 Apr 2011 02:11

hello. 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

Note: this part - "C:\Program Files (x86)\iOpus\iMacros\iMacros.exe" -macro "screenshot.iim" -var_offercode %%G

will be executed within the next 4 hours before going to 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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Nested For /F in batch reading input from txt

#2 Post by aGerman » 07 Apr 2011 02:32

Not sure, but try something like that:

Code: Select all

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

Regards
aGerman

lizac
Posts: 3
Joined: 07 Apr 2011 02:08

Re: Nested For /F in batch reading input from txt

#3 Post by lizac » 07 Apr 2011 02:54

hi! Thanks... by the way, I should have included what's included in the ANOTHER COMMAND

So the entire content of my .bat file is


FOR /F "tokens=* delims= " %%G in (partners.txt) DO "C:\Program Files (x86)\iOpus\iMacros\iMacros.exe" -macro "screenshot.iim" -var_offercode %%G
pushd C:\Users\U460\Documents\iMacros\ImageMagick
set MYPATH=%CD%
FOR /F %%A in ('compare -metric AE first.png second.png diff.png 2^>^&1') DO set Diff=%%A
ECHO %Diff%
if "%Diff%"=="0" (exit) else wscript C:\Users\U460\Documents\iMacros\Tests\SendsEmail.vbs
pause

I tried replacing the ANOTHER COMMAND with the code above from "pushd" but it's giving me an error that windows cannot find such command. but it's still executing the command. Can you further help? Thank you so much.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Nested For /F in batch reading input from txt

#4 Post by aGerman » 07 Apr 2011 04:21

Try:

Code: Select all

FOR /F "tokens=* delims= " %%G in (partners.txt) DO (
  start "" /wait "C:\Program Files (x86)\iOpus\iMacros\iMacros.exe" -macro "screenshot.iim" -var_offercode %%G
  setlocal enabledelayedexpansion
  pushd C:\Users\U460\Documents\iMacros\ImageMagick
  set MYPATH=!CD!
  FOR /F %%A in ('compare -metric AE first.png second.png diff.png 2^>^&1') DO set Diff=%%A
  ECHO !Diff!
  if "!Diff!"=="0" (exit) else wscript C:\Users\U460\Documents\iMacros\Tests\SendsEmail.vbs
  popd
  endlocal
)

Regards
aGerman

lizac
Posts: 3
Joined: 07 Apr 2011 02:08

Re: Nested For /F in batch reading input from txt

#5 Post by lizac » 07 Apr 2011 06:58

works like a charm. Thank you for being so helpful!
GodSpeed!

Post Reply