Nested For /F in batch reading input from txt

April 7, 2011 at 01:05:47
Specs: Windows 7 Home edition
0 down vote favorite

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.

Thanks a lot!

See More: Nested For /F in batch reading input from txt

Report •

April 7, 2011 at 03:33:33
FOR /F "tokens=* delims= " %%G in (partners.txt) DO (
  "C:\Program Files (x86)\iOpus\iMacros\iMacros.exe" -macro "screenshot.iim" -var_offercode %%G

Report •

April 7, 2011 at 04:50:25
Thanks, Ivo. I've read a lot of your posts here and they are all helpful. Anyways,
just a follow up. I'm trying to use the same variable in the ANOTHER COMMAND but it's not rendering.

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

The second %%G is not rendering on second call. Can you help me further? Thank you so much!

Report •

April 7, 2011 at 04:58:41
To add more, can I also pass the value of %%G to a CDO email as argument? How? Thanks so much!

Report •

Related Solutions

April 7, 2011 at 05:18:30
Hi! again. No need to respond on my second question. I just learned that I no longer need to use the same variable.

Anyways, I still have hanging question re. the passing of value of %%G to CDO email in vbscript. Is that possible? How?


Report •

April 7, 2011 at 07:15:26
Hi lizac,

I am not experienced with VBScript and the one advice I can give you to pass a parameter is to set an envitonment variable and then access it inside the VBScript.

This method however works only for a VBScript called inside the same batch script setting the variable since the environment is not persistent when the batch ends.

As example:

set VBParam=%%G
Your VBScript

The above inside your For loop.

Report •

April 8, 2011 at 01:58:26
hello IVO. I'm getting Subscript out of range error. here's my code:

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
FOR /F %%A in ('compare -metric AE first.png second.png diff.png 2^>^&1') DO set Diff=%%A
if "%Diff%"=="0" (exit) else set VBParam=%%G wscript SendsEmail.vbs

batch is calling the vbscript. which is SendsEmail.vbs.
1. Is the list line correct?
2. How will I call it in vbscript? I want to be able to add it in the body of the email.

Sorry, I'm just starting to learn. Thanks so much!

Report •

April 8, 2011 at 03:08:43
Hi lizac,

in the batch script you posted there are so many mistakes that is easier for me to recode it from scratch than to explain step by step. The most relevant is the misuse of environment and internal variables in a FOR loop.

As I said I am glad to give you the revised script version, but , please tell me, do you have to use absolutely a VBScript to mail or may a generic smtp line mailer suffice?
Let me know and maybe better you contact me by a private message with your e-mail address.

Report •

April 8, 2011 at 03:20:15
Hi. IVO. As you already know from my coding ability I'm definitely a newbie. I would love to know my errors and thank you for offering the revision. I don't necessarily need to use the vbscript for sending email but it's the only way I know that's working for sending email. I'm open to a working batch email option. I'll send you the copy of it. Thank you thank you for saving me.

Report •

Ask Question