![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 06:39 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS开发编程 & 发展交流 (开发室) » [Sharing] How to set the ERRORLEVEL value in a DOS environment |
| Printable Version 2,179 / 4 |
| Floor1 willsort | Posted 2004-02-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
To All:
The ERRORLEVEL value in a DOS environment is generally produced when an external program exits, but in some situations we need to produce the errorlevel value ourselves. The following batch files show several methods for setting ERRORLEVEL. Because of system-related factors, none of them have been tested. If anyone is willing to do so, I'd be very grateful for corrections! Also, for a program to get the errorlevel value, see: http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=6&ID=9358 |
|
| Floor2 willsort | Posted 2004-02-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
:: Seterror.bat - First version
:: This is my first algorithm, implemented with pure batch processing, and it has many limitations :: It can only set 0-9 and 255; all other values are treated as "large values" and set to 10 @echo off if == goto end if == goto setzero if == goto setmax for %%a in (1 2 3 4 5 6 7 8 9) do if == goto set1to9 goto setbig :setzero echo exist> test.txt find "exist" test.txt > nul del test.txt goto end :set1to9 choice /c:123456789 /t:%1,1 /n > nul goto end :setbig choice /c:123456789a /t:a,1 /n > nul goto end :setmax choice /d /n > nul goto end :end |
|
| Floor3 willsort | Posted 2004-02-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
::Seterror.bat - Second version
::Below is an assembly-language algorithm that calls subfunction 4Ch of DOS interrupt int21 ::When using it, the first parameter must be a two-digit hexadecimal number @echo off if == goto end :main echo a>seterror.asd echo mov ax,4c%1>>seterror.asd echo int21>>seterror.asd echo.>>seterror.asd echo g>>seterror.asd echo q>>seterror.asd debug nul :check call geterror.bat @ if == if not == goto error if not == echo Set current errorlevel is %el% goto end :error echo. echo Error: Invalid argument "%1" echo. goto end :end |
|
| Floor4 willsort | Posted 2004-02-07 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
:: Seterror.bat - Third version
:: This is an improved version of the assembly program, with radix conversion code added, so decimal parameters can be used :: Handling of invalid parameters: :: 22e-->22 e22-->0 256-->0 65535-->255 65536-->0 @echo off if == goto end if exist seterror.com goto run if exist seterror.asd goto debug :setscript echo >seterror.asd A100 echo>>seterror.asd MOV SI,0082 echo>>seterror.asd XOR AX,AX echo>>seterror.asd XOR BX,BX echo>>seterror.asd MOV CX,000A echo>>seterror.asd MOV BL, echo>>seterror.asd CMP BL,30 echo>>seterror.asd JL 0120 echo>>seterror.asd CMP BL,39 echo>>seterror.asd JG 0120 echo>>seterror.asd SUB BL,30 echo>>seterror.asd MUL CX echo>>seterror.asd ADD AX,BX echo>>seterror.asd INC SI echo>>seterror.asd JMP 010A echo>>seterror.asd MOV AH,4C echo>>seterror.asd INT 21 echo.>>seterror.asd echo>>seterror.asd R CX echo>>seterror.asd 24 echo>>seterror.asd W echo>>seterror.asd Q :debug debug SETERROR.COM nul :run seterror.com %1 if not errorlevel %1 goto error if not == if errorlevel %1 echo Current errorlevel is set. if exist geterror.bat call geterror.bat %3 ::if exist seterror.com del seterror.com ::if exist seterror.asd del seterror.asd goto end :error echo. echo Error: Fail to set current errorlevel. echo. goto end :end |
|
| Floor5 willsort | Posted 2004-03-02 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
This is Horst Schaeffer's assembly version. It also supports decimal parameters, but it's more organized than the one I wrote myself, and it also includes a command-line prompt. To use it, save the following text into the file el!.txt, then enter "debug < el!.txt" at the DOS command line to get the el!.com file. At runtime, the usage is "el! the errorlevel value you want to set".
A 100 |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |