Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - redirection operators as syntactic suger

Reply
 
Old 07-08-2009   #1 (permalink)
Larry__Weiss


 
 

redirection operators as syntactic suger

Bruce Payette has written

myScript > file.txt
is just syntactic sugar for
myScript | out-file -path file.txt

What would be the equivalent PowerShell statements for the other
output redirection operators?
Quote:
Quote:

>>
2>
2>&1

- Larry Weiss

My System SpecsSystem Spec
Old 07-09-2009   #2 (permalink)
Chris Dent


 
 

Re: redirection operators as syntactic suger


Hi Larry,

Those are implemented in PowerShell as is.

See:

Get-Help about_redirection

Or the rather better help file from 2.0:

http://technet.microsoft.com/en-us/l.../dd315283.aspx

Chris
My System SpecsSystem Spec
Old 07-09-2009   #3 (permalink)
Joel Bennett


 
 

Re: redirection operators as syntactic suger

Yeah, as Chris said, all of those are built-in to PowerShell and work
just as expected. I've been wracking my brain trying to think of a
out-file equivalent for the others ....

1) myScript > file.txt
myScript | Out-File file.txt
2) myScript >> file.txt
myScript | Out-File file.txt -Append


Sadly, although they implemented the 2> and 2>& operators, and ADDED
"warning" and "verbose" and "debug" output pipes .... they didn't add
any redirection operators for the new pipes, nor did they add anything
beyond those 2> and 2>& for controlling the output of those...

Until PowerShell 2.0

In 2.0, if you have CmdletBinding you can use variable redirection for
the Warning and Error pipes, but not Verbose or Debug.

-WarningVariable $outWarning
-ErrorVariable $outError

So basically, if myScript.ps1 had a first line:
[CmdletBinding()]

You could do all sorts of variations on this:

myScript -OutVariable +output -ErrorVariable +output
Out-File file.txt -InputObject $output

--
Joel



Larry__Weiss wrote:
Quote:

> Bruce Payette has written
>
> myScript > file.txt
> is just syntactic sugar for
> myScript | out-file -path file.txt
>
> What would be the equivalent PowerShell statements for the other
> output redirection operators?
>
Quote:
Quote:

> >>
> 2>
> 2>&1
>
> - Larry Weiss
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Powershell Operators PowerShell
CTP2 comparison operators PowerShell
Subexpressions and Unary Operators PowerShell
ansi versus unicode output with redirection operators? PowerShell
Bit Operators PowerShell


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46