0

I am trying to write a batch script that executes the following set of commands:

for /f "delims=: tokens=2" %I in ('ipconfig^|findstr /I /C:"Default Gateway . . . . . . . . . : 192.168"') do SET gw=%I if "%gw%" == " 192.168.1.1" \\server\script.cmd if "%gw%" == " 192.168.2.1" \\server\script2.cmd if "%gw%" == " 192.168.3.1" \\server\scripts3.cmd 

The problem is when the FOR statement runs the SET command the script will exit before the rest of the commands are ran.

What I need the batch script to do is set the 'gw' variable and then continue with the rest of the commands.

FYI: The script is suppose to parse the gateway of the computer and then run another script based on that info. All of the commands run from within the 'cmd' window when executed separately.

1 Answer 1

1

You have to double the % of the FOR is variable in a .Bat file :

for /f "delims=: tokens=2" %%I in ('ipconfig^|findstr /I /C:"Default Gateway . . . . . . . . . : 192.168"') do SET gw=%%I if "%gw%" == " 192.168.1.1" \\server\script.cmd if "%gw%" == " 192.168.2.1" \\server\script2.cmd if "%gw%" == " 192.168.3.1" \\server\scripts3.cmd 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.