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 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
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“
这个帖子”和“
这个帖子”并努力遵守,如果可能,请告诉更多的人!