Windows batch files: how to compare a command line argument with an integer

I am only new to batch file programming, and I tried to find a solution on the Internet, but could not. My batch file calls program c, passing it its own command line arguments to the program, and then performs the following steps, which depend on the value of the fourth argument (integer). I would like to take an extra step in my batch file if% 4 is 3. I posted a few echo verification instructions. But only "testno" is printed, even if I enter 3 as my fourth argument.


Batch file name: p2debug1234.bat


Batch File Code:


@echo off @setlocal p2task1 %1 %2 %3 %4 start mi_viewer %1 start mi_viewer %2 echo %4 echo 3 If ("%4"== "3") (echo testyes) Else (echo testno) echo testif 

Command line snapshot:


 H:\ELEC4622\labs\data>p2debug1234 pens_rgb.bmp test.bmp 2 3 3 3 testno testif 

Please help me make a reliable comparison.

Best regards, Julia

+6
source share
1 answer

Change line:

 If ("%4"== "3") (echo testyes) Else (echo testno) 

in

 If "%4"=="3" (echo testyes) Else (echo testno) 
+10
source

Source: https://habr.com/ru/post/955331/


All Articles