#!/usr/bin/env pwsh
1..100 | foreach {
$response= invoke-restmethod www.azuredevops.com/api/v2/somequery
Write-Output "string showing the status of CI pipeline" # i don't want this to go into pipe
cls
}
Write-Output "formated string which contains Build details in json format which will be outputted to the pipeline"
上面的腳本將在 windows-powershell 和 linux-powershell 中運行。在這個腳本中,我將列印“ status/progress ”和“ result_output ”,然后將它們輸出到管道。目前,腳本的狀態/進度輸出正在以所需的輸出字串輸出到管道。在將進度和所需輸出列印到終端時,如何僅將所需的輸出限制為管道。
uj5u.com熱心網友回復:
基于Mathias 的有用評論,PowerShell 具有內置 cmdlet 來與其不同的流進行互動,所有這些都在about_Output_Streams中進行了描述。默認情況下可以捕獲的唯一流是成功流(標準輸出),并且大多數可以重定向到它,但與問題無關。有關這方面的更多資訊,請參閱about_Redirection。
這是上面解釋的一個小例子,它可以讓您了解如何處理您的代碼。
function ReceiveFromPipeline {
param([Parameter(ValueFromPipeline)] $InputObject)
process {
"Receiving [$InputObject] from pipeline"
}
}
$result = 1..100 | ForEach-Object {
# this is Standard Output,
# will be received by ReceiveFromPipeline function
$_
# This goes to the Info Stream and will not be captured in `$result`
# unless redirected.
Write-Host "Writing [$_] to the Information Stream"
# This goes to the Progress Stream, cannot be redirected!
Write-Progress -Activity "[$_] goes to the Progress Stream"
Start-Sleep -Milliseconds 200
} | ReceiveFromPipeline
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512843.html
標籤:电源外壳壳终端
上一篇:生成兩個單詞的隨機序列
