Before I start, here is a handy tip. When you are trying out a batch script, don't start it from Windows Explorer (by doubling clicking its icon). If you do this any errors
can, and successfully reaching the end of the script
will make the command window abruptly vanish. You can trap the script termination with a pause command, but if there is a prior error the window may vanish too quickly for you to read the error message.
So run the script from a command window by typing its name and any parameter(s) at the prompt, this is easiest if you are in the same folder then you can just type its name and optionally its extension. The long winded way to get there is to type "cmd" in the Run box from the Start menu, and then navigate to the folder using CD. The quicker way is to use "Command Prompt here" from a right click on the folder in Windows Explorer. This is built in to Vista and later, with earlier Windows versions see here
http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htmRunning the script this way means that when it terminates either at the end or because of a syntax error, or doesn't do what you expect, you get the prompt back and in the case of an error you see the script output and any error messages and this is available for you to look at, and in the event of mystification, to copy and paste it into a search engine or as part of a post in a help forum such as this one.
Now to the matter in hand:
You don't need 2 batch files.
The general syntax of FOR is
On one line:
FOR ["
options"] %%
variable in (
dataset) DO
commandUsing parentheses you can make it span multiple command lines (many people indent the interior for readability):
FOR ["
options"] %%
variable in (
dataset) DO (
command1 command2 command3 etc
)
["
options"] may not always be present. Can contain skip= eol= tokens= delims= sections.
variable is a single letter from A-Z a-z.
dataset can one or more files, wild cards can be used.
To apply
command to every line of a file you would use the /F switch
Thus
FOR /F %%A in (filename.txt) DO ping %%A
or
@echo off
for /f %%A in (ip-addresses.txt) do (
ping %%A
tracert %%A
)
echo.
echo *** loop completed ***
echo.
pause
Here is a text file (It has 2 lines but could have more). I have called it ip-addresses.txt
87.248.112.81
209.85.229.99
Running the above batch code produces this output at my location:
Pinging 87.248.112.81 with 32 bytes of data:
Reply from 87.248.112.81: bytes=32 time=41ms TTL=53
Reply from 87.248.112.81: bytes=32 time=51ms TTL=52
Reply from 87.248.112.81: bytes=32 time=40ms TTL=53
Reply from 87.248.112.81: bytes=32 time=44ms TTL=53
Ping statistics for 87.248.112.81:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 40ms, Maximum = 51ms, Average = 44ms
Tracing route to fe15.global.sports.ird.yahoo.com [87.248.112.81]
over a maximum of 30 hops:
1 8 ms 7 ms 7 ms 10.15.176.1
2 7 ms 7 ms 7 ms aztw-geam-1b-ge212.network.virginmedia.net [80.1.243.137]
3 7 ms 7 ms 7 ms aztw-core-1b-ae0-0.network.virginmedia.net [80.1.241.13]
4 13 ms 10 ms 9 ms brhm-bb-1b-as1-0.network.virginmedia.net [213.105.175.161]
5 13 ms 13 ms 13 ms nrth-bb-1a-as4-0.network.virginmedia.net [62.253.185.105]
6 11 ms 11 ms 11 ms nrth-tmr-1-ae1-0.network.virginmedia.net [213.105.159.30]
7 31 ms 31 ms 33 ms fran-ic-1-as0-0.network.virginmedia.net [62.253.185.81]
8 27 ms 27 ms 64 ms ge-1-3-0.pat1.dee.yahoo.com [80.81.192.115]
9 26 ms 27 ms 29 ms so-2-0-0.pat1.ams.yahoo.com [66.196.65.144]
10 44 ms 45 ms 43 ms UNKNOWN-66-196-65-X.yahoo.com [66.196.65.81]
11 44 ms 52 ms 43 ms ae-1.msr1.ird.yahoo.com [66.196.67.231]
12 47 ms 46 ms 79 ms te-7-4.bas-b1.ird.yahoo.com [87.248.101.103]
13 41 ms 52 ms 53 ms fe15.global.sports.ird.yahoo.com [87.248.112.81]
Trace complete.
Pinging 209.85.229.99 with 32 bytes of data:
Reply from 209.85.229.99: bytes=32 time=25ms TTL=53
Reply from 209.85.229.99: bytes=32 time=25ms TTL=53
Reply from 209.85.229.99: bytes=32 time=25ms TTL=52
Reply from 209.85.229.99: bytes=32 time=26ms TTL=52
Ping statistics for 209.85.229.99:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 25ms, Maximum = 26ms, Average = 25ms
Tracing route to ww-in-f99.1e100.net [209.85.229.99]
over a maximum of 30 hops:
1 6 ms 7 ms 7 ms 10.15.176.1
2 8 ms 7 ms 8 ms aztw-geam-1b-ge136.network.virginmedia.net [80.1.242.121]
3 7 ms 7 ms 7 ms aztw-core-1b-ae0-0.network.virginmedia.net [80.1.241.13]
4 9 ms 9 ms 9 ms brhm-bb-1b-as1-0.network.virginmedia.net [213.105.175.161]
5 11 ms 11 ms 11 ms manc-bb-1a-as6-0.network.virginmedia.net [62.253.185.134]
6 12 ms 13 ms 17 ms manc-bb-1b-ae0-0.network.virginmedia.net [62.253.187.178]
7 78 ms 22 ms 19 ms tele-ic-3-ae0-0.network.virginmedia.net [212.43.163.70]
8 21 ms 19 ms 19 ms 138-14-250-212.static.virginmedia.com [212.250.14.138]
9 20 ms 20 ms 19 ms 209.85.252.76
10 26 ms 25 ms 25 ms 72.14.232.134
11 72 ms 26 ms 28 ms 216.239.49.45
12 25 ms 33 ms 29 ms 209.85.243.85
13 27 ms 25 ms 20 ms ww-in-f99.1e100.net [209.85.229.99]
Trace complete.
*** loop completed ***
Press any key to continue . . .
You don't say why you are using "eol=" in the options block. If it is not used, you can comment out lines in the text file simply with a semicolon.
Thus in this text file, using my above syntax, the third line will be ignored:
87.248.112.81
209.85.229.99
;212.58.224.138
212.250.162.12
By the way, this is an ip address:
209.85.229.99
and this is (part of) a url:
www.yahoo.com