Batch file doesn't exit the loop correctly?

I am working on a batch file to collect mac addresses from my two subnet clients, but for some reason my batch file does not finish the first loop correctly, so the second loop is not executed and hence the rest of the script is not 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

      

Thank you very much in advance

EDIT: ping.bat contains just the following:

nbtstat -A %1.%2

      

To get MAC address via NetBIOS

0


a source to share


2 answers


Running the batch file interrupts the batch file "mother". Although she appears to be ending the current line; your first FOR loop actually runs 254 times.

Adding a CALL statement will 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

      

+2


a source


Most likely, he is waiting for a response from the other end. Didn't you try to shorten the time? I suggest you add a dummy counter to check if it's awaiting a response or hung. :-)



0


a source







All Articles