简体   繁体   English

Windows批处理文件:如何将命令行参数与整数进行比较

[英]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 ac 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). 我的批处理文件调用ac程序将它自己的命令行参数传递给程序,然后执行后续步骤,这些步骤取决于第四个参数的值(这是一个整数)。 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. 如果%4等于3,我想在我的批处理文件中执行额外的步骤。我已经放置了一些echo测试语句。 But only the "testno" gets printed even if I enter 3 as my fourth argument. 但即使我输入3作为我的第四个参数,也只会打印“testno”。


Batch file name: p2debug1234.bat 批处理文件名: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 最诚挚的问候,朱莉娅

Change line: 换线:

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

to: 至:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM