Wednesday, February 27, 2013

Batch File Looping - Route, Ping, …

You create a batch file called route.bat or route.cmd and it contains something similar to the following:

echo off
Route add 10.1.0.0 MASK 255.255.0.0 10.50.5.125
exit

When you run it as an Administrator it never finishes. You remove the “echo off” to see what is going on. You run it again and see it in an endless loop. When you cut and paste the command “route add…” in an Administrative command prompt  it works as expected but your batch file keeps looping.

Solution:

Never name your batch file the same name as the executable it runs.

The reason in the example is the naming of the batch file is “route.” and your batch file is calling out to run the command “route”, It is executing itself in a never ending loop. Renaming the batch file something other than “route” and it will work fine.

Happy Batch Creation!

2 comments:

  1. Exactly the problem I had. Changed the name and now works perfectly. Many thanks. Charlie

    ReplyDelete