PowerShell Pipeline Concept如何工作? [英] How does the PowerShell Pipeline Concept work?

查看:77
本文介绍了PowerShell Pipeline Concept如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解PowerShell管道通过将一个cmdlet的输出作为输入传递给另一个cmdlet来工作.但是如何做到这一点呢?

I understand that PowerShell piping works by taking the output of one cmdlet and passing it to another cmdlet as input. But how does it go about doing this?

第一个cmdlet是否完成,然后一次传递所有输出变量,然后由下一个cmdlet处理?

Does the first cmdlet finish and then pass all the output variables across at once, which are then processed by the next cmdlet?

还是第一个cmdlet的每个输出一次取一个,然后遍历所有其余管道cmdlet的输出?

Or is each output from the first cmdlet taken one at a time and then run it through all of the remaining piped cmdlet’s?

推荐答案

您可以通过简单的脚本了解管道顺序的工作方式:

You can see how pipeline order works with a simple bit of script:

function a {begin {Write-Host 'begin a'} process {Write-Host "process a: $_"; $_} end {Write-Host 'end a'}}
function b {begin {Write-Host 'begin b'} process {Write-Host "process b: $_"; $_} end {Write-Host 'end b'}}
function c { Write-Host 'c' }

1..3 | a | b | c

输出:

begin a
begin b
process a: 1
process b: 1
process a: 2
process b: 2
process a: 3
process b: 3
end a
end b
c

这篇关于PowerShell Pipeline Concept如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆