欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

dos中一些常用命令的errorlevel返回值

 更新時間:2021年06月29日 09:37:15   投稿:mdxy-dxy  
這篇文章主要介紹了dos中一些常用命令的errorlevel返回值,方便大家在bat中方便判斷

Windows DOS(或批處理) 對命令執(zhí)行結(jié)果(返回碼)的判斷,可使用errorlevle值來進行。例如

IF %ERRORLEVEL% GTR 0 GOTO end

表示查找jar命令,當(dāng)沒有找到時,則跳轉(zhuǎn)到“end” 子程序繼續(xù)執(zhí)行。

 IF %ERRORLEVEL% GTR 0 ECHO 錯誤代碼:%errorlevel%

表示找不到j(luò)ar命令時,則打印錯誤代碼。

if %ERRORLEVEL%對數(shù)值的比較方法有如下幾種:

EQU - 等于
NEQ - 不等于
LSS - 小于
LEQ - 小于或等于
GTR - 大于
GEQ - 大于或等于

ATTRIB.EXE

(a) Target file/folder not found                            = ERRORLEVEL 1
(b) Invalid switch                                                 = ERRORLEVEL 1
(c) Sharing violation (target file in use)               = ERRORLEVEL 1
(d) Invalid drive specification                              = ERRORLEVEL 1
(e) Drive not ready (either Abort or Fail reply)    = ERRORLEVEL 1
(f) Invalid/wrong number of parameters              = ERRORLEVEL 1

EXTRACT.EXE

(a) Invalid switch                                  = ERRORLEVEL 1

FC.EXE

(a) Insufficient number of filespecs                = ERRORLEVEL 1
(b) Too many filenames on command line              = ERRORLEVEL 1
(c) Sharing Violation + Abort reply                 = ERRORLEVEL 5
     (Note: Fail reply returns ERRORLEVEL 0)
(d) Drive not ready                                 = ERRORLEVEL 18
     (Note: Fail reply returns ERRORLEVEL 0)

FIND.EXE

(a) Target string found    (=f0und)                  = ERRORLEVEL 0
(b) Target string missing (=m1ssing)             = ERRORLEVEL 1
(c) find /?                                         = ERRORLEVEL 1
(d) Parameter format not correct                    = ERRORLEVEL 2
(e) Specified file to search not found              = ERRORLEVEL 2
(f) Specified file in use + Fail reply                  = ERRORLEVEL 2
(g) Drive not ready + Fail reply                        = ERRORLEVEL 2
(h) Specified file in use + Abort reply              = ERRORLEVEL 5
(i) Drive not ready + Abort reply                    = ERRORLEVEL 5

FORMAT.COM

(a) Drive not ready                                 = ERRORLEVEL 4
     (There is no Abort, Retry, Fail stall)

FTP.EXE

(a) Brief help (use: ftp -h for Brief help)         = ERRORLEVEL 2
(b) Error opening script file (file missing)        = ERRORLEVEL 2
(c) Invalid switch                                  = ERRORLEVEL 2

MORE.COM

(a) Invalid switch (MORE doesn't accept switches)   = ERRORLEVEL 1
(b) Drive not ready (Abort reply)                   = ERRORLELEL 5
     (Note: Fail reply returns ERRORLEVEL 0)

MOVE.EXE

(a) Required parameter missing                      = ERRORLEVEL 1
(b) Unable to create destination                    = ERRORLEVEL 1
(c) Unable to open source                           = ERRORLEVEL 1
     (you see this when trying to MOVE a folder from one drive
      to another. You need to use XCOPY /S followed by DELTREE,
      since MOVE won't handle folder moves across drives)
(d) Sharing violation + Fail reply                  = ERRORLEVEL 1
     (Note: file is nevertheless COPIED, not moved, in this case)
(e) Sharing violation + Abort reply                 = ERRORLEVEL 5
     (Note: file is nevertheless COPIED, not moved, in this case)
(f) Drive not ready (Abort reply)                   = ERRORLEVEL 18
     (Note: Fail reply - unusually - returns ERRORLEVEL 1)

PING.EXE

(a) Unknown host                                    = ERRORLEVEL 1
     (usually=name not found on DomainNameServer)
(b) Brief help (with no parameter)                  = ERRORLEVEL 1
Note: for PING Brief help with /? switch, ERRORLEVEL is 0
(c) Invalid switch                                  = ERRORLEVEL 1
     (and displays the Brief help as well)
(d) Interrupted with [Ctrl-C]                       = ERRORLEVEL 255

SORT.EXE

(a) Invalid switch                                  = ERRORLEVEL 1
(b) Drive not ready (Abort reply)                   = ERRORLEVEL 15
     (Note: Fail reply returns ERRORLEVEL 0)

START.EXE

(a) start /? (real mode)                            = ERRORLEVEL 1
(b) start /? (GUI)                                  = ERRORLEVEL 255
(c) Can't find file specified for START             = ERRORLEVEL 255
(d) No file association for specified file          = ERRORLEVEL 255
(e) Drive not ready                                 = ERRORLEVEL 255
     (There is no Abort, Retry, Fail stall)

SUBST.EXE

(a) Invalid parameter                               = ERRORLEVEL 1
(b) Invalid switch                                  = ERRORLEVEL 1
(c) Path not found                                  = ERRORLEVEL 1
(d) Drive not ready (Abort reply)                   = ERRORLEVEL 21
     (Note: Fail reply - unusually - returns ERRORLEVEL 1)

TRACERT.EXE

(a) Unable to resolve target system name            = ERRORLEVEL 1
     (usually=name not found on DomainNameServer)
(b) Invalid switch                                  = ERRORLEVEL 1
(c) Brief help (no parameter)                       = ERRORLEVEL 1
(d) Interrupted with [Ctrl-C]                       = ERRORLEVEL 255
Note: for TRACERT Brief help, type command without parameters

XCOPY.EXE

(a) File not found                                  = ERRORLEVEL 1
(b) Invalid date in /d switch                       = ERRORLEVEL 4
(c) Invalid number of parameters                    = ERRORLEVEL 4
(d) Invalid parameter                               = ERRORLEVEL 4
(e) Device not ready                                = ERRORLEVEL 4
(f) Unable to create directory                      = ERRORLEVEL 4
(g) System can't find file                          = ERRORLEVEL 5
     (this occurs when device such as NUL is used as Source file)

if結(jié)合errorlevel使用

說明:環(huán)境變量errorlevel的初始值為0,當(dāng)一些命令執(zhí)行不成功,就會返回一個數(shù)值,如:1 ,2 等

IF-ERRORLEVEL

測試代碼:

@ECHO OFF
XCOPY F:\test.bat D:\
IF ERRORLEVEL 1 ECHO 文件拷貝失敗
IF ERRORLEVEL 0 ECHO 成功拷貝文件

如果文件拷貝成功,屏幕就會顯示“成功拷貝文件”,否則就會顯示“文件拷貝失敗”。
IF ERRORLEVEL 是用來測試它的上一個DOS命令的返回值的,注意只是上一個命令的返回值,而且返回值必須依照從大到小次序順序判斷。
因此下面的批處理文件是錯誤的:

@ECHO OFF
XCOPY C:\AUTOEXEC.BAT D:\
IF ERRORLEVEL 0 ECHO 成功拷貝文件
IF ERRORLEVEL 1 ECHO 未找到拷貝文件
IF ERRORLEVEL 2 ECHO 用戶通過ctrl-c中止拷貝操作
IF ERRORLEVEL 3 ECHO 預(yù)置錯誤阻止文件拷貝操作
IF ERRORLEVEL 4 ECHO 拷貝過程中寫盤錯誤

無論拷貝是否成功,后面的:
未找到拷貝文件
用戶通過ctrl-c中止拷貝操作
預(yù)置錯誤阻止文件拷貝操作
拷貝過程中寫盤錯誤
都將顯示出來。

以下就是幾個常用命令的返回值及其代表的意義:

backup

0 備份成功
1 未找到備份文件
2 文件共享沖突阻止備份完成
3 用戶用ctrl-c中止備份
4 由于致命的錯誤使備份操作中止
diskcomp
0 盤比較相同
1 盤比較不同
2 用戶通過ctrl-c中止比較操作
3 由于致命的錯誤使比較操作中止
4 預(yù)置錯誤中止比較
diskcopy
0 盤拷貝操作成功
1 非致命盤讀/寫錯
2 用戶通過ctrl-c結(jié)束拷貝操作
3 因致命的處理錯誤使盤拷貝中止
4 預(yù)置錯誤阻止拷貝操作

format

0 格式化成功
3 用戶通過ctrl-c中止格式化處理
4 因致命的處理錯誤使格式化中止
5 在提示“proceed with format(y/n)?”下用戶鍵入n結(jié)束

xcopy

0 成功拷貝文件
1 未找到拷貝文件
2 用戶通過ctrl-c中止拷貝操作
4 預(yù)置錯誤阻止文件拷貝操作
5 拷貝過程中寫盤錯誤

if還有一個特殊的用法就是可以用來檢測某個變量是否已經(jīng)被定義

用法示例:

@echo off
set “str1=ok”
set “str2=no”
if defined str1 echo str1已經(jīng)被定義
if defined str2 echo str2已經(jīng)被定義
if defined str3 (echo str3已經(jīng)被定義) else echo str3 沒有被定義
pause>nul

if errorlevel 0
===> 表示errorlevel 等于或大于0

if not errorlevel 0
===> 表示errorlevel 小于0

if %errorlevel% == 0 或者 if “%errorlevel%” == “0 ” 或 if “%errorlevel%” equ “0 ”
===> 表示errorlevel 等于0

if %errorlevel% neq 0 或者 if “%errorlevel%” neq “0 ” 或 if “%errorlevel%” neq “0 ”
===> 表示errorlevel 不等于0

到此這篇關(guān)于dos中一些常用命令的errorlevel返回值的文章就介紹到這了,更多相關(guān)errorlevel返回值內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論