China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 20:53
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Help] What kind of null device is nul 2? View 730 Replies 8
Original Poster Posted 2005-03-11 00:00 ·  中国 北京 方正宽带
初级用户
Credits 141
Posts 11
Joined 2004-09-30 00:00
21-year member
UID 31972
Gender Male
Status Offline
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
Floor 2 Posted 2005-03-11 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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 &gt. 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 abcd
Volume 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
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-03-11 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
DVBBS forums really suck, I just absolutely can’t make it bold.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 4 Posted 2005-03-11 00:00 ·  中国 北京 方正宽带
初级用户
Credits 141
Posts 11
Joined 2004-09-30 00:00
21-year member
UID 31972
Gender Male
Status Offline
I really am very grateful to climbing~~~~~~~~~~~~~~~~echo Thx climbing very much 1>nul 2>nul
Floor 5 Posted 2005-03-11 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Come on, if you echo it like that, then there’s no thanks at all, geez~~~
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2005-03-11 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Haha, you two are really humorous! So NUL has this kind of trick to it too.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 7 Posted 2005-03-11 00:00 ·  中国 北京 联通
初级用户
Credits 141
Posts 11
Joined 2004-09-30 00:00
21-year member
UID 31972
Gender Male
Status Offline
The following is quoted from Climbing’s post at 2005-3-11 18:34:30:

Come on, if you echo it like that, then there’s no thanks at all, geez~~~

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.
Floor 8 Posted 2005-03-13 00:00 ·  中国 福建 三明 电信
中级用户
★★
Credits 316
Posts 83
Joined 2005-03-01 00:00
21-year member
UID 36626
Gender Male
Status Offline
^_^ Nice
Floor 9 Posted 2005-03-13 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
The following is quoted from Climbing’s post at 2005-3-11 13:01:59:

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 &gt. 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:
D:\XYF\System\dos>dir abcd
Volume in drive D is HDAL2_WORK
Volume Serial Number is 58BA-2D5D
Directory of D:\XYF\System\dos
File Not Found
D:\XYF\System\dos>dir abcd > nul
File Not Found
D:\XYF\System\dos>dir abcd 1> nul
File Not Found
D:\XYF\System\dos>dir abcd 1> nul 2>nul
D:\XYF\System\dos>dir abcd >nul 2>nul
D:\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

Today I learned some good stuff again
http://www.msfans.net/bbs/
Forum Jump: