Variable comparision in a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sirisha
Posts: 1
Joined: 30 Aug 2015 22:40

Variable comparision in a batch file

#1 Post by sirisha » 30 Aug 2015 23:00

Hi,I have a batch file in which i need to call two other batches depending on a condition.

And the condition is, i have two variables in a text file(Two strings.For Eg:2016JanFcst and 2016FebFcst).Now i have two read these two variables from my batch and check if these two are equal.

And if these two variables are equal i have to call one batch else the other one.

Can anyone let me know how this can be achieved?

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Variable comparision in a batch file

#2 Post by Meerkat » 31 Aug 2015 03:22

Sample.txt

Code: Select all

2016JanFcst
2016FebFcst


Code snippet:

Code: Select all

@echo off
(
   set /p var1=
   set /p var2=
)<"Sample.txt"

   ::Uncomment the next line just to make sure the two strings are captured...
   ::echo."%var1%" "%var2%"

if "%var1%"=="%var2%" (
   call "Code1.bat"
) else (
   call "Code2.bat"
)


Meerkat

Post Reply