0

I have a very noob issue on using variables on a ROUTE ADD syntax of a batch-file. In poor words I ask for inputting 2 value, then I use them to create 2 specific IP addresses and then I want to pass them to the ROUTE ADD syntax, but on my OS (Windows7 x64), when I run the script I can see correctly the IP01 and IP02 variables, but I cannot have the ROUTE ADD command to recognize IP01 and IP02... even I put %IP01% and %IP02% the command displayed writes nothing on the screen and so I cannot continue processing the batch file. Same problem also with PING command.

Here is the original code I've written:

@ECHO OFF
REM ******************************
REM ROUTE MAP for ENDIA-eWON
REM ******************************

CLS
ECHO.
COLOR 0A
ECHO.+ROUTE MAP 10.128.X.0 with eWON-sn + IP 172.31.1.X
ECHO.+PING ROUTE JUST DEFINED, TO CHECK IT
ECHO.----------------------------
ECHO.Author: aColussi@atomat.com
ECHO.v1.00
ECHO.
ECHO.
ECHO.
SET /P RGWsn=Insert eWON sn (RGWsn):
SET /P EndianIP=Insert last value X for the Endian network (172.30.1.X):

REM ******************************
REM DEFINE IP01 (eWON network) and IP02 (ENDIAN network)
REM ******************************

SET IP01 = 10.128.%RGWsn%.0
SET IP02 = 172.30.1.%EndianIP%

REM TEST THE 2 VALUES JUST DEFINED
SET IP01
SET IP02
PAUSE

@ECHO ON
REM ADD THE ROUTE
ROUTE ADD %IP01% MASK 255.255.255.0 %IP02% METRIC 1
PAUSE

@ECHO OFF
REM TEST THE ROUTE AND THE PING OF THE eWON ASSOCIATED DEVICE (.254)
ECHO.
ECHO.VIEW THE ROUTES ON OUR WORKSTATION
ROUTE PRINT |MORE
PAUSE
ECHO.
ECHO.PING-TEST FOR THE JUST-ADDED ROUTE/IP (USING eWON .254)
SET IP03 = 10.128.%RGWsn%.254
PING %IP03%
PAUSE
Serge Wautier
  • 21,494
  • 13
  • 69
  • 110

1 Answers1

4

You have the problem when you are doing the SET. the SET for "RGWsn" and "EndianIP" is fine, but at other places, the spaces are causing the problem.

SET IP01 = 10.128.%RGWsn%.0

With this you are creating a variable "IP01 " and setting its value to " 10.128.%RGWsn%.0" Notice the spaces here.

You should be doing

SET IP01=10.128.%RGWsn%.0

Similarly for IP02 and IP03.

Take a look at this similar problem.

Community
  • 1
  • 1
manimatters
  • 424
  • 3
  • 11
  • you are saying that you can't do `ping (spaces here) 127.0.0.1`? – nikodz Sep 09 '13 at 09:15
  • No, I am saying that your variable names have extra spaces. In your case you will have to do a PING %IP01 %. Your variable name is "IP01 " with a space. – manimatters Sep 09 '13 at 09:17
  • Many thanks for Manimatters and Epsilon replies. That was exactly the mistake I made. With SET IP01 I was calling all the variables who start with IP01 and that's why the system replied with the IP01 variable... while for the initial space at the beginning, now I fixed it and all is working fine. Thanks again. – Andrea Colussi Sep 09 '13 at 10:26