2

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

Moe
  • 462
  • 2
  • 16
  • 3
    theoretically both syntaxes are interchangable. Theoretically... For [certain reasons](https://stackoverflow.com/a/28260620/2152082) the first is safer. – Stephan Jul 06 '17 at 19:55

1 Answers1

3

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.

Anders
  • 97,548
  • 12
  • 110
  • 164