2017-05-05 83 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