這篇文章主要介紹了dos中一些常用命令的errorlevel返回值,方便大家在bat中方便判斷
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)