Search code examples
windowsbatch-filecmdnul

>nul redirection before or after command in batch


In command prompt, the following two lines give the same output, I want to know the usage difference between them. Thanks.

>nul dir

dir >nul


Solution

  • There is no difference, they redirect the same amount of output. You can combine the input and output redirection operators in multiple ways: > out.txt command < in.txt or < in.txt command > out.txt.

    As noted in the comments, you have to be careful if something contains the number 1 or 2, you don't want %something%>out.txt to expand to ...2>out.txt and you can do that with a space or by putting it before the rest of the command.