Reputation:
I am working on a batch file to gather the mac addresses of two of my subnets clients however for some reason my batch file is not ending the first loop correctly, so the second loop is not being executed and thus the rest of the script is not being executed. Any ideas on why this is happening?
for /L %%i in (1,1,254) do ping.bat 192.168.232 %%i
for /L %%i in (1,1,254) do ping.bat 192.168.233 %%i
REM Some other stuff goes on here but the second loop never gets executed
Thanks a lot in advance
EDIT: ping.bat contains simply this:
nbtstat -A %1.%2
To get the MAC address via NetBIOS
Upvotes: 0
Views: 1371
Reputation: 238078
Starting a batch file aborts the "mother" batch file. Although she appears to finish the current line; your first FOR loop actually gets executed 254 times.
Adding a CALL statement would fix this:
for /L %%i in (1,1,254) do call ping.bat 192.168.232 %%i
for /L %%i in (1,1,254) do call ping.bat 192.168.233 %%i
echo Test complete!
Before the CALL statement was introduced, this was solved by running the child batch file in a new instance of the command interpreter:
for /L %%i in (1,1,254) do COMMAND /C ping.bat 192.168.232 %%i
Upvotes: 2
Reputation: 20906
Most probably it is waiting for the response from the other end. Didn't you try reducing the time out? I suggest you to add a dummy counter to check whether it is waiting for response or hanged.. :-)
Upvotes: 0