Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am only very new to batch file programming and I have tried to find the solution online, but failed. My batch file calls a c program passing it's own command line arguments to the program then does subsequent steps which depend on the value of the fourth argument (which is an integer). I would like to do an extra step in my batch file if %4 is equal to 3. I have placed some echo test statements. But only the "testno" gets 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 prompt snapshot:


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

3
3
testno
testif

Please help me make a valid comparison.

Best Regards, Julia

like image 712
user2851154 Avatar asked Oct 06 '13 06:10

user2851154


1 Answers

Change line:

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

to:

If "%4"=="3" (echo testyes) Else (echo testno)
like image 56
joojaa Avatar answered Sep 28 '22 21:09

joojaa