I'm writing a bat script for automatically creating /32 routes towards devices in a network reachable trough a LAB tunnel interface. 

I have to do this because the LAB tunnel has to be set upon an other one (corporate tunnel) that automatically forwards packets inside of it if there is no routes for the destination. Consequently I create all /32 routes for devices in the network in order to prevent forwarding the corporate tunnel.

Following script makes the trick but for an unknown reason to me, I have to run it 3 or 4 times before it works. (Note I'm a big noob with bat script)

```
@echo off
c:
cd %systemroot%
set /P input=Please enter a LAB ID:
set /A labid=%input%
if %labid% GTR 98 ( 
    if %labid% LSS 255 (
        set "net=10.%labid%"
        for /f "tokens=1-5 delims= " %%A in ('route print ^| findstr %net%') do (
            echo Adding static routes for LAB %labid%...
            set gatewayssl=%%C
            echo Gateway is SSL interface: %gatewayssl%
            for /l %%h in (1,1,254) do call :add_route %%h %gatewayssl%
            goto:EOF
        )
        goto:EOF
    )else (
        echo Invalid Lab ID
        goto:EOF
    )
) else (
    echo Invalid Lab ID
        goto:EOF
)

:add_route
set ipaddr=%net%.0.%1
route add %ipaddr% mask 255.255.255.255 %2% metric 1
goto:EOF

```

Typically, here is the ouput produced:

```
[...]>Z:\ALU\SGCC\LAB\labrouting.bat
Please enter a LAB ID:104
FINDSTR : Ligne de commande erronée

C:\WINNT>Z:\ALU\SGCC\LAB\labrouting.bat
Please enter a LAB ID:104
Adding static routes for LAB 104...
Gateway is SSL interface:

Manipule les tables de routage du réseau.

ROUTE [-f] [-p] [cmde [destin]
[route manual apperas many times because of the for loop...]

C:\WINNT>Z:\ALU\SGCC\LAB\labrouting.bat
Please enter a LAB ID:104
Adding static routes for LAB 104...
Gateway is SSL interface: 192.168.104.1

```

As you can, after running this script 3 times, it finally works. 
Could you please help to identify what causes this issue ?

I thank you in advance for your very appreciated support.

Best regards,

Sylvain.