confussing batch behavior

  • Thread starter Thread starter yawnmoth
  • Start date Start date
Y

yawnmoth

Say I have a batch script - test.cmd (or test.bat - I don't think it
matters) - with the following contents:

dir > test.txt

Why, when I run it, is the following command run?:

dir 1>test.txt

The end result is the same, but the fact that it's doing something that
it shouldn't, no matter how seemingly benign, kinda worries me...
 
yawnmoth said:
Say I have a batch script - test.cmd (or test.bat - I don't think it
matters) - with the following contents:

dir > test.txt

Why, when I run it, is the following command run?:

dir 1>test.txt

The end result is the same, but the fact that it's doing something that
it shouldn't, no matter how seemingly benign, kinda worries me...

You write "the fact that it's doing something that it shouldn't".
This is not a fact - it's pure fiction. Windows has two streams
to catch screen output from a command:
1> . . . (for informative output)
2> . . . (for error messages)

If you don't specify a number then informative output will be directed
by default to the device specified after the arrow heads. In other
words, the commands
dir 1>test.txt and
dir >test.txt
will do exactly the same thing.
 
Back
Top