Microsoft DOS if command

转载 2011年01月20日 16:12:00

 

转自 http://www.computerhope.com/batch.htm

 

Windows 95, Windows 98, and Windows ME syntax

Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

NOT Specifies that Windows should carry out the command only if the condition is false.
ERRORLEVEL number Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.
command Specifies the command to carry out if the condition is met.
string1==string2 Specifies a true condition if the specified text strings match.
EXIST filename Specifies a true condition if the specified filename exists.

Windows 2000 and Windows XP syntax

Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

NOT Specifies that Windows 2000 / XP should carry out the command only if the condition is false.
ERRORLEVEL number Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.
string1==string2 Specifies a true condition if the specified text strings match.
EXIST filename Specifies a true condition if the specified filename exists.
command Specifies the command to carry out if the condition is met. Command can be followed by ELSE command that will execute the command after the ELSE keyword if the specified condition is FALSE

The ELSE clause must occur on the same line as the command after the IF. For
example:

IF EXIST filename. (
del filename.
) ELSE (
echo filename. missing.
)

The below example would NOT work because the del command needs to be terminated by a newline:

IF EXIST filename. del filename. ELSE echo filename. missing

Nor would the below example work, since the ELSE command must be on the same line as the end of the IF command:

IF EXIST filename. del filename.
ELSE echo filename. missing

The below example would work if you want it all on one line:

IF EXIST filename. (del filename.) ELSE echo filename. missing

If Command Extensions are enabled IF changes as follows:

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

where compare-op may be one of:

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. The /I switch can also be used on the string1==string2 form of IF. 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.

The CMDEXTVERSION conditional works just like ERRORLEVEL, except it is comparing against an internal version number associated with the Command Extensions. The first version is 1. It will be incremented by one when significant enhancements are added to the Command Extensions. CMDEXTVERSION conditional is never true when Command Extensions are disabled.

The DEFINED conditional works just like EXISTS except it takes an environment variable name and returns true if the environment variable is defined.

%ERRORLEVEL% will expand into a string representation of the current value of ERRORLEVEL, provided that there is not already an environment variable with the name ERRORLEVEL, in which case you will get its value instead. After running a program, the below example illustrates ERRORLEVEL use:

goto answer%ERRORLEVEL%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1

You can also using the numerical comparisons above:

IF %ERRORLEVEL% LEQ 1 goto okay

%CMDCMDLINE% will expand into the original command line passed to CMD.EXE prior to any processing by CMD.EXE, provided that there is not already an environment variable with the name CMDCMDLINE, in which case you will get its value instead.

%CMDEXTVERSION% will expand into the a string representation of the current value of CMDEXTVERSION, provided that there is not already an environment variable with the name CMDEXTVERSION, in which case you will get its value instead.

 

相关文章推荐

error: command 'C:\\Users\\Mrchang\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Pyt

安装scrapy异常解决办法: set STATICBUILD=true && pip install lxml 异常信息: Collecting Scrapy==1.1.1   Do...

Microsoft IIS FTP Service CVE-2012-2532 Remote Command Injection Vulnerability

Microsoft IIS is prone to a remote command-injection vulnerability because it fails to adequately sa...

List of FTP commands for the Microsoft command-line FTP client

List of raw FTP commands (Warning: this is a technical document, not necessary for most FTP use.) ...

DOS Command

一、常用DOS命令 FDISK(硬盘分区) 外部命令 FORMAT(磁盘格式化) 外部命令 CHKDSK(磁盘检查) 外部命令 磁盘操作类 DISKCOPY(全盘拷贝) 外部命令 DISKC...

dos command

XP.CMD命令大全 转载请注明出自雨林木风 bbs.ylmf.com,本贴地址:http://bbs.ylmf.com/read.php?tid=623689&u= 有关某个命令的详细信息,...

Start Windows Process / DOS Command

1. Start Windows Process / DOS command  public static Process SystemExecuteBG(String command, bool ...

DOS命令应用之IF-ERRORLEVEL

if errorlevel n (语句段) 是dos命令行中用来处理错误的语句,大部分命令或程序执行之后都会返回一个变量errorlevel 这个变量是命令行内置的变量,代表错误等级,它的正规运用...

DOS/BAT批处理if exist else 语句的几种用法

转自:http://www.xue51.com/tuwen/4454.html 一、批处理if书写格式 if 条件表达式 (语句1) else (语句2),它的含义是:如果条件表达式成立,...

How can I get my public IP address from the command line, if I am behind a router?

24down voteaccepted Assuming your system has 2 ethernet devices, eth0 and eth1 and eth0 is con...

dos的 if语句

dos的 if语句 使用   if用于条件判断,适用于以下情形:   1、判断驱动器、文件或文件夹是否存在,用 if exist 语句;   2、判断某两个字符串是否相等,用 if "字...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)