I need execute two commands on Windows 7 startup (with .bat file):
route delete 0.0.0.0 192.168.5.201
route -p add 192.168.4.0 mask 255.255.0.0 192.168.5.201
If first route doesn’t exists on system – .bat file doesn’t executes properly. First command executes on infinity loop.
How can i check if this route exists and then execute first command?
P.S. or maybe there is another way to do it without .bat file?
I cannot reproduce the infinite loop here; for me it just exits with an error.
But you can check for a particular route with
However, that alone won’t be enough as the exit code of
routeis always 0. So you have to pipe throughfindstr:Afterwards you can either check
errorlevel:or chain the command: