2017-05-05 58 views
-1

我得到了这个疑问,请人解释概念批量脚本

@echo off 
:: take any number between 1 to 1619 it is true 
if ERRORLEVEL == 0 echo There was a problem with the command error returned %errorlevel% 
echo 0 
if ERRORLEVEL == 1 echo There was a problem with the command error returned %errorlevel% 
echo 1 
if ERRORLEVEL == 1619 echo There was a problem with the command error returned %errorlevel% 
echo 1619 
:: greater than 1619 false 
if ERRORLEVEL == 1620 echo There was a problem with the command error returned %errorlevel% 
echo 1620 
if ERRORLEVEL == 658547 echo There was a problem with the command error returned %errorlevel% 
echo 658547 
:: any negative number true 
if ERRORLEVEL == -1620 echo There was a problem with the command error returned %errorlevel% 
echo -1620 
if ERRORLEVEL == -63653 echo There was a problem with the command error returned %errorlevel% 
echo -63653 

为什么呢?任何背后的概念?

+2

它要么'如果%ERRORLEVEL%== 5'(正是 “5”)或'如果ERRORLEVEL 5'( “5” 或更高版本)。当然'如果'也有“LSS”,“GTR”等等。参见'if /?' – Stephan

回答

0

您正在执行的命令是一样的

if errorlevel 0 echo something 

检查if /? output.And因为=在这里批量标准分隔符它没有考虑到。 if errorlevel命令检查errorlevel是否大于或等于给定的数字。如果你想精确比较的动态变量%errorlevel%使用编译:

if %errorlevel% equ 0 echo something