控制檯流

PS> $ErrorActionPreference = "Continue" (1)
PS> & console_app.exe *>&1 | % { $_ } (2)
PS> & console_app.exe *>&1 | ? { $_ -is [System.Management.Automation.ErrorRecord] } (3)
PS> & console_app.exe *>&1 | ? { $_ -is [System.Management.Automation.WarningRecord] } (4)
PS> & console_app.exe *>&1 | ? { $_ -is [System.Management.Automation.VerboseRecord] } (5)
PS> & console_app.exe *>&1 (6)
PS> & console_app.exe 2>&1 (7)

流 2 包含 System.Management.Automation.ErrorRecord 物件。請注意,某些應用程式(如 git.exe)使用錯誤流作為參考目的,根本不一定是錯誤。在這種情況下,最好檢視退出程式碼以確定錯誤流是否應該被解釋為錯誤。

PowerShell 瞭解這些流:輸出,錯誤,警告,詳細,除錯,進度。本機應用程式通常只使用這些流:輸出,錯誤,警告。

在 PowerShell 5 中,可以將所有流重定向到標準輸出/成功流(6)。

在早期的 PowerShell 版本中,只有特定的流可以重定向到標準輸出/成功流(7)。在此示例中,錯誤流將重定向到輸出流。