Ask Leo!

Re: [Fwd: Ask Leo Question] - Windows Command Line redirection operators

Home
««   »»

From Leo's mailbag:

> From: A Computer User
> Sent: October 30, 2007
> To: Ask Leo!
> Subject: Re: [Fwd: Ask Leo Question] - Windows Command Line redirection operators
>
> Leo,
> In "What is 'defragging', and why should I do it?"
> you give the line:
>
> defrag c: >c:\defrag.log 2>&1
>
> I would feel better if I knew what the "2>&1" meant.
> 1. Would you please explain that "argument".
> 2. Would you please refer me to some document/site/etc.
> where I could learn about these "args".

Command line programs often output to the screen in two "streams",
one called "standard output" (stream #1) and the other called
"standard error" (stream #2).

The ">c:\defrag.log" says "write standard output to the file
C:\defrag.log". "2>&1" says "write standard error to the same place
you're writing standard output.

The difference is this: if this command generates an error:

defrag >c:\defrag.log

Then the error will be written to the screen, but other program
output will be sent to the file.

defrag >c:\defrag.log 2>&1

ensures that both the error message and the regular output will be
sent to the file.

If you search Windows XP Help for "redirection" you'll see a topic
called "Using command redirection operators" that describes these in
more detail.

--
Thanks for asking,

Leo Notenboom

Article 1678 | Category: Windows

Google
ask-leo.com
Web