![]() |
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-08-27 09:59 |
47,812 topics / 349,912 posts / today 0 new / 48,264 members |
| 其它操作系统综合讨论区 » Can SET change the value of errorlevel? |
| Printable Version 809 / 3 |
| Floor1 gqtc | Posted 2007-10-25 19:51 |
| 初级用户 Posts 15 Credits 38 | |
|
1: The single SET command can view the system environment variables. errorlevel is also a system variable, so why can't I see it?
2: Can set errorlevel=n change the value of errorlevel? For example: set errorlevel=5 echo %errorlevel% The result shows 5 But if errorlevel 5 echo haha doesn't display anything at all. Why? I'm confused, and hope the experts won't hesitate to enlighten me. Thanks! |
|
| Floor2 Climbing | Posted 2007-10-26 16:01 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
if %errorlevel%==5 echo ok
errorlevel is an implicit dynamic environment variable, just like %date% and %cd%. Also, its value should be set automatically by the system. Although you can manually set its value with the SET command, that only means you defined an environment variable named errorlevel yourself. |
|
| Floor3 Climbing | Posted 2007-10-26 16:08 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
After you manually set an environment variable named errorlevel, the system variable with the same name stops working. That means that when you access it with %errorlevel%, you only get the value you defined yourself, while at that point the system's errorlevel can only be accessed with if errorlevel.
F:\WORK\DOS>set errorlevel= F:\WORK\DOS>echo %errorlevel% 1 F:\WORK\DOS>set errorlevel=a F:\WORK\DOS>echo %errorlevel% a F:\WORK\DOS>echo %errorlevel% | find /i "a" a F:\WORK\DOS>if errorlevel 1 echo not found. F:\WORK\DOS>if errorlevel 0 echo found. found. F:\WORK\DOS>if %errorlevel%==0 echo found. F:\WORK\DOS>echo %errorlevel% | find /i "b" F:\WORK\DOS>if errorlevel 1 echo not found. not found. F:\WORK\DOS>if errorlevel 0 echo found. found. F:\WORK\DOS>if %errorlevel%==1 echo found. F:\WORK\DOS>set errorlevel= F:\WORK\DOS>if %errorlevel%==1 echo found. found. |
|
| Floor4 gqtc | Posted 2007-10-26 18:41 |
| 初级用户 Posts 15 Credits 38 | |
|
Thanks to both of you for your answers, I understand now.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |