Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Redirection and discarding of error objects

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-25-2007   #1 (permalink)
Hans Dingemans
Guest


 

Redirection and discarding of error objects

Bruce Payette's book, page 259, has an example showing capturing error info
in a variable other than $error, and suppressing the errors being displayed:

PS> dir nofuss, nomuss, nobother -ErrorVariable errs 2>$null

Obviously, these are non-existing files and indeed $errs.count equals 3.
However, I do not understand the constant 2 in the command. If I leave it
out, or fill in some other number, the errors are sent to the console.
What's the magic of 2 here, why 2? It must be something simple I overlooked,
or is it just time for coffee?

Thanx,
Hans



My System SpecsSystem Spec
Old 09-25-2007   #2 (permalink)
Jon
Guest


 

Re: Redirection and discarding of error objects


"Hans Dingemans" <hans_dingemans@xxxxxx> wrote in message
news:%23mxy$u0$HHA.4496@xxxxxx
Quote:

> Bruce Payette's book, page 259, has an example showing capturing error
> info in a variable other than $error, and suppressing the errors being
> displayed:
>
> PS> dir nofuss, nomuss, nobother -ErrorVariable errs 2>$null
>
> Obviously, these are non-existing files and indeed $errs.count equals 3.
> However, I do not understand the constant 2 in the command. If I leave it
> out, or fill in some other number, the errors are sent to the console.
> What's the magic of 2 here, why 2? It must be something simple I
> overlooked, or is it just time for coffee?
>
> Thanx,
> Hans
>


2> is the standard notation for error output (ie where to send error
messages), as 1> or > is for standard output. So in that particular case no
errors appear on the screen, since they're sent to '$null', but they are
sent to the variable $errs.


The following is taken from the output from this command, and may help

get-help about_Operator


Redirection Operators
2>&1 Add errors to results
1>&2 Add results to errors
Quote:
Quote:

>> Append results to a file
> Create a file with results, previous file contents are
overwritten
< Input from (not supported)
2>> Append errors to a file
2> Errors from operation are directed to named file, previous
file contents are overwritten

--
Jon


My System SpecsSystem Spec
Old 09-25-2007   #3 (permalink)
Jeff
Guest


 

Re: Redirection and discarding of error objects

On Sep 25, 3:11 pm, "Hans Dingemans" <hans_dingem...@xxxxxx>
wrote:
Quote:

> Bruce Payette's book, page 259, has an example showing capturing error info
> in a variable other than $error, and suppressing the errors being displayed:
>
> PS> dir nofuss, nomuss, nobother -ErrorVariable errs 2>$null
>
> Obviously, these are non-existing files and indeed $errs.count equals 3.
> However, I do not understand the constant 2 in the command. If I leave it
> out, or fill in some other number, the errors are sent to the console.
> What's the magic of 2 here, why 2? It must be something simple I overlooked,
> or is it just time for coffee?
>
> Thanx,
> Hans
'2>' is the redirection operator specifically for errors; there really
isn't a constant '2' in the command. The number 2 is used for
historical reasons, I assume; the handle for the standard error I/O
stream on a Unix system is 2. You can read about all of the
redirection operators supported by PowerShell starting on page 138 of
Bruce's book.

Jeff

My System SpecsSystem Spec
Old 09-25-2007   #4 (permalink)
Hans Dingemans
Guest


 

Re: Redirection and discarding of error objects

Thanx to both for quick and detailed answers; the network at its best!


"Hans Dingemans" <hans_dingemans@xxxxxx> wrote in message
news:%23mxy$u0$HHA.4496@xxxxxx
Quote:

> Bruce Payette's book, page 259, has an example showing capturing error
> info in a variable other than $error, and suppressing the errors being
> displayed:
>
> PS> dir nofuss, nomuss, nobother -ErrorVariable errs 2>$null
>
> Obviously, these are non-existing files and indeed $errs.count equals 3.
> However, I do not understand the constant 2 in the command. If I leave it
> out, or fill in some other number, the errors are sent to the console.
> What's the magic of 2 here, why 2? It must be something simple I
> overlooked, or is it just time for coffee?
>
> Thanx,
> Hans
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Folder Redirection Error John Whites Vista General 0 08-11-2008 01:43 PM
closing, discarding, saving, undo disks, oh my... michael sorens Virtual PC 3 07-24-2008 04:07 PM
Why version with redirection output run with error? David Kriz PowerShell 1 07-04-2008 12:16 PM
Error using mandatory roaming profile and Folder Redirection wasserja Vista General 10 08-27-2007 05:09 AM
Sane error redirection? kelanslists@gmail.com PowerShell 3 03-06-2007 04:49 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008