views:

22

answers:

2

So, I think I may be going insane. This batch script:

@Echo on
dir > dir.txt

generates the following on the console it is run from:

dir  1>dir.txt

I expected to see simply dir > dir.txt. Any ideas why this is happening? This is on Windows XP SP2 in the standard command prompt.

+3  A: 

The 1 is the file descriptor for standard output. Therefore, these two commands are equivalent.

As a side note, you can redirect errors by redirecting descriptor 2, like this:

myCommand 1>goodoutput.txt 2>errors.txt

There's a nice summary of what you can do with redirection here.

Michael Myers
A: 

Your redirection operator (>) is essentially sending your command output to the stdout (standard output). "1" is the stdout handler.

You can also pipe to the stderr (error output); like in UNIX by using the "2" handler.

e.g myprogram.exe >> myoutput.txt 2>&1

For more information, see Command Redirection

Syd