0

I am creating a batch script where I have to compare versions and then proceed with the installation. I am getting error @ when I use or (||) in if. How do I compare two conditions in one if? I tried using a for loop by creating a list of values and then comparing. This is also giving me an error.

@echo off

set "python_ver=Python 3.7"

set "python_major=(not found)"
set "python_minor=(not found)"

FOR /f "tokens=1,2 delims=." %%a IN ("%python_ver%") do set 
python_major=%%a & set python_minor=%%b

FOR /f "tokens=1,2 delims= " %%a IN ("%python_major%") do set 
python_major=%%b 

if %python_major%==3 (
    if %python_minor% LSS 5 or  if  %python_minor% GTR 6 (
        echo version not supported. should be 3.5 or 3.6
    ) else (
        echo go to install
    )
) else (
    echo Please update your python
)
aschipfl
  • 33,626
  • 12
  • 54
  • 99
gaurav2907
  • 51
  • 1
  • 9
  • 1
    is `%phyton_major%` really meant to be `Python 3`? You should better use token 2 and 3 with delims= dot and space: `FOR /f "tokens=2,3 delims=. " %%a in ...` – Stephan Jul 17 '18 at 14:14
  • [The Windows command prompt is *NOT* a DOS prompt!](https://scalibq.wordpress.com/2012/05/23/the-windows-command-prompt-is-not-a-dos-prompt/) – aschipfl Jul 17 '18 at 14:15
  • `if` can't do things like `AND` or `OR` – Stephan Jul 17 '18 at 14:16
  • Try `if %python_minor% LSS 5 (echo version not supported. should be 3.5 or 3.6) else (if %python_minor% GTR 5 (echo go to install))` – John Kens Jul 17 '18 at 14:19
  • this is working fine......... but when i add or to second if it shows error . I have to add another condtion that id %python_minor% is gtr 6 then also it should not allow. if %python_major%==3 ( if %python_minor% LSS 5 ( echo version not supported. should be 3.5 or 3.6 ) else ( echo go to install ) ) else ( echo Please update your python ) – gaurav2907 Jul 17 '18 at 14:54

0 Answers0