![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-09-15 06:55 |
共 47,812 主题排行 / 349,917 发帖 / 今日 0 篇 / 48,268 会员排行 |
| DOS开发编程 & 发展交流 (开发室) » [分享]如何设置DOS环境中的ERRORLEVEL值 |
| 可打印版本 2,181 / 4 |
| 第1楼 willsort | 发表于 2004-02-06 00:00 |
| 元老会员 发帖 1,512 积分 4,432 | |
|
[分享]如何设置DOS环境中的ERRORLEVEL值 To All:
DOS环境中的ERRORLEVEL值一般由外部程序退出时产生,但在某种情况下我们需要自己产生errorlevel值。 以下批处理程序就是关于设置ERRORLEVEL的若干方法,因为系统因素均未经测试,请有心者代劳,敬谢指正! 另外,获取errorlevel值的程序可见: http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=6&ID=9358 |
|
| 第2楼 willsort | 发表于 2004-02-06 00:00 |
| 元老会员 发帖 1,512 积分 4,432 | |
|
:: Seterror.bat - First version
:: 这是我的第一个算法,用单纯批处理实现,有很多限制 :: 只能设置0-9和255,其它值均作为“大值”被设置为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 |
|
| 第3楼 willsort | 发表于 2004-02-06 00:00 |
| 元老会员 发帖 1,512 积分 4,432 | |
|
::Seterror.bat - Second version
::以下是一个汇编算法,调用了dos提供的int21中断4c子功能 ::使用时第一参数必须是两位16进制数 @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 |
|
| 第4楼 willsort | 发表于 2004-02-07 00:00 |
| 元老会员 发帖 1,512 积分 4,432 | |
|
:: Seterror.bat - Third version
:: 这是汇编程序的改进版,加入了进制转换代码,可以使用十进制参数了 :: 对于非法的参数处理: :: 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 |
|
| 第5楼 willsort | 发表于 2004-03-02 00:00 |
| 元老会员 发帖 1,512 积分 4,432 | |
|
这是 Horst Schaeffer 的汇编版本,同样支持十进制数参数,不过比我自己编得更条理一些,而且加上了命令行提示。使用时可以将以下文本保存入 el!.txt 文件中,然后在 dos 命令行输入 “debug < el!.txt” 即可得到 el!.com 文件。运行时用法为 “el! 想设置的 errorlevel 值”。 A 100 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |