Redirecting command-line output to keep error messages from showing in the command window
问题 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 ( echo/FOLDER DOES NOT EXIST ) else ( echo/FOLDER EXISTS ) The problem is that if the folder doesn't exist I'm getting this error in addition to the standard output: The system cannot find the file specified. I'd like to display the correct output without getting the error. 回答1: How about this: DIR %MYDIR%\tmp > nul 2>&1 "> nul" means to redirect