Redirecting command-line output to keep error messages from showing in the command window

后端 未结 3 1929
孤独总比滥情好
孤独总比滥情好 2021-01-16 10:29

I\'m testing the existence of a folder, and, depending on its existence, I want to run different commands:

DIR %MYDIR%\\tmp > test.txt
IF ERRORLEVEL 1 (
          


        
3条回答
  •  -上瘾入骨i
    2021-01-16 11:13

    How about this:

    DIR %MYDIR%\tmp > nul 2>&1
    

    "> nul" means to redirect standard output to the file nul (the bit bucket).

    "2>" is used to redirect standard error (descriptor 2). So "2>&1" is used to redirect standard error to means that standard output (descriptor 1 -- so "> null and 1> null are be the same). Alternatively you could use "2> nul".

提交回复
热议问题