简体   繁体   English

如果在批处理文件中

[英]IF in batch file

If I do (MyVar is set to "hi" value) 如果我这样做(将MyVar设置为“ hi”值)

IF %MyVar% == "hi" ( Echo Hi )

Then I got Output 然后我得到输出

Hi

But If I do ( ProgramFile(x86) is set to C:\\Program Files (x86)) 但是如果我这样做(ProgramFile(x86)设置为C:\\ Program Files(x86))

IF %ProgramFiles(x86)% == "C:\Program Files (x86)" ( Echo Hi )

then I got Out put 然后我就把

Files was unexpected at this time.

If I do: 如果我做:

 IF "%ProgramFiles(x86)%" == "C:\Program Files (x86)" ( Echo Hi )

Then I got NO output 然后我没有输出

Why output is not coming properly in case of ProgramFile(x86) environment variable? 为什么在ProgramFile(x86)环境变量的情况下输出不正确?

If Command Extensions are enabled IF changes as follows: If启用了命令扩展,则IF更改如下:

  • IF [/I] string1 compare-op string2 command
  • IF CMDEXTVERSION number command
  • IF DEFINED variable command

where compare-op may be one of: 其中compare-op可能是以下之一:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

and the /I switch, if specified, says to do case insensitive string compares. /I开关(如果指定)表示执行不区分大小写的字符串比较。 The /I switch can also be used on the string1==string2 form of IF. /I开关也可以用于IF的string1==string2形式。 These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed. 这些比较是通用的,因为如果string1和string2都由所有数字组成,则将字符串转换为数字并执行数字比较。

using compare-op with /I can be better; 使用带有/I compare-op会更好;

so you can try this code: 因此您可以尝试以下代码:

IF /I "%ProgramFiles(x86)%" equ "C:\Program Files (x86)" (echo Hi)

But maybe the commend text is invalid: 但是,也许推荐的文字是无效的:

The CMDEXTVERSION conditional works just like ERRORLEVEL, except it is comparing against an internal version number associated with the Command Extensions. CMDEXTVERSION条件条件与ERRORLEVEL一样,只不过它与与命令扩展关联的内部版本号进行比较。 The first version is 1. It will be incremented by one when significant enhancements are added to the Command Extensions. 第一个版本是1。当对命令扩展进行了重大增强时,它将增加一个。 CMDEXTVERSION conditional is never true when Command Extensions are disabled. 禁用命令扩展时,CMDEXTVERSION条件永远不会为真。

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

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