DevOps by Default Blog

Prompt for input in Windows CMD batch script

Occasionally you may be writing a DOS Windows CMD batch program and want input from the user at run time. For just such an occasion, you can use the set /p command.

In this example below, we ask the user to enter an IP address, then we use the captured input to set the next hop for each of the routes.

There is no validation in this example, its just quick and dirty.

@echo off
set /p NEXTHOP="Enter the next hop for these few static routes: " %=%

route -p add 10.10.10.111 mask 255.255.255.255 %NEXTHOP% metric 1
route -p add 10.10.10.202 mask 255.255.255.255 %NEXTHOP% metric 1

Comments