HOW THE PIPELINE WORKS

Pipeline

Pipline

A pipeline is a series of commands separated by the pipe operator (|), each command in the pipeline receives an object from the previous command, performs some operation on it, and then passes it along to the next command in the pipeline.

 

Streaming Behavior

In stream processing, objects are output from the pipeline as soon as they become available. In more traditional programming environments, the results are returned only when the entire result set has been generated—the first result and the last result are returned at the same time. In a pipelined shell, the first result is returned as soon as it’s available and subsequent results return as they also become available.

In most shell environments, streaming is accomplished by using separate processes for each element in the pipeline. In PowerShell, which only uses a single process (and a single thread as well), streaming is accomplished by splitting cmdlets into three clauses: BeginProcessing, ProcessRecord, and EndProcessing. In a pipeline, the BeginProcessing clause is run for all cmdlets in the pipeline. Then the ProcessRecord clause is run for the first cmdlet. If this clause produces an object, that object is passed to the ProcessRecord clause of the next cmdlet in the pipeline, and so on. Finally the EndProcessing clauses are all run.

 

Parameter Binding Debug Command

Trace-Command -Name ParameterBinding -Option All -Expression { 123 | Write-Output } –PSHost

 

Formatting Cmdlets

Get-Command Format-* | Format-Table name

Name
----
Format-Custom
Format-List
Format-Table
Format-Wide

 

Outputter Cmdlets

Get-Command Out-* | Format-Table Name

Name
----
Out-Default - The default outputter
Out-File - This command sends the result to a file
Out-GridView – Displays the output in a grid, but rather than rendering the output in the current console window, a new window is opened with the output displayed
Out-Host - It sends its output back to the host
Out-Null – Anything sent to Out-Null is simply discarded
Out-Printer - It routes its text-only output to the printer
Out-String - Formats its input and sends it as a string to the next cmdlet in the pipeline

posted @ 2012-11-23 19:04  HelloWorld.Michael  阅读(143)  评论(0编辑  收藏  举报