![]() |
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-17 06:52 |
47,813 topics / 349,903 posts / today 0 new / 48,259 members |
| DOS疑难解答 & 问题讨论 (解答室) » [Help] What kind of null device is nul 2? |
| Printable Version 766 / 8 |
| Floor1 32211001 | Posted 2005-03-11 00:00 |
| 初级用户 Posts 11 Credits 141 | |
|
In batch files I often see statements like this, starting with an echo, and ending with “>nul 2>nul”.
nul is a null device, so what is nul 2? If you want the output not to be shown, wouldn’t just >nul be enough? Why is there also nul 2 in front? Thanks for all your replies |
|
| Floor2 Climbing | Posted 2005-03-11 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
It’s not nul 2, but 2> nul, which means the error messages are also sent to the null device, that is, even the error messages are not shown. Under normal circumstances, a command outputs its results to standard output, and standard output is represented by 1, so the >nul you typed is actually 1>nul (note that there cannot be a space between 1 and >
. But during the execution of some commands, error messages are displayed. >nul cannot hide these error messages, because these error messages do not belong to standard output, but to standard error output. Standard error output is represented by 2, so 2> nul means not to display error messages. For example, take the dir command (the bold part indicates the prompt and command line, and what follows is the command’s execution result) :\XYF\System\dos>dir abcdVolume in drive D is HDAL2_WORK Volume Serial Number is 58BA-2D5D Directory of D:\XYF\System\dosFile Not FoundD:\XYF\System\dos>dir abcd > nul File Not FoundD:\XYF\System\dos>dir abcd 1> nul File Not FoundD:\XYF\System\dos>dir abcd 1> nul 2>nulD:\XYF\System\dos>dir abcd >nul 2>nulD:\XYF\System\dos>dir abcd 2>nul Volume in drive D is HDAL2_WORK Volume Serial Number is 58BA-2D5D Directory of D:\XYF\System\dos |
|
| Floor3 Climbing | Posted 2005-03-11 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
DVBBS forums really suck, I just absolutely can’t make it bold.
|
|
| Floor4 32211001 | Posted 2005-03-11 00:00 |
| 初级用户 Posts 11 Credits 141 | |
|
I really am very grateful to climbing~~~~~~~~~~~~~~~~echo Thx climbing very much 1>nul 2>nul
|
|
| Floor5 Climbing | Posted 2005-03-11 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Come on, if you echo it like that, then there’s no thanks at all, geez~~~
|
|
| Floor6 JonePeng | Posted 2005-03-11 00:00 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
Haha, you two are really humorous! So NUL has this kind of trick to it too.
|
|
| Floor7 32211001 | Posted 2005-03-11 00:00 |
| 初级用户 Posts 11 Credits 141 | |
The following is quoted from Climbing’s post at 2005-3-11 18:34:30: Sorry about that. It was just a way of expressing my feelings. Just take it as me not saying thanks out loud; in fact I’m already very grateful in my heart. |
|
| Floor8 smileseeker | Posted 2005-03-13 00:00 |
| 中级用户 Posts 83 Credits 316 | |
|
^_^ Nice
|
|
| Floor9 chenhui530 | Posted 2005-03-13 00:00 |
| 高级用户 Posts 273 Credits 772 | |
The following is quoted from Climbing’s post at 2005-3-11 13:01:59: Today I learned some good stuff again |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |