Page 1 of 1

Nested For /F in batch reading input from txt

Posted: 07 Apr 2011 02:11
by lizac
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.

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

Posted: 07 Apr 2011 02:32
by aGerman
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

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

Posted: 07 Apr 2011 02:54
by lizac
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.

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

Posted: 07 Apr 2011 04:21
by aGerman
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

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

Posted: 07 Apr 2011 06:58
by lizac
works like a charm. Thank you for being so helpful!
GodSpeed!