about_Output_Streams

简短说明

说明 PowerShell 中输出流的可用性和用途。

长说明

PowerShell 提供多个输出流。 这些流为不同类型的消息提供通道。 可以使用关联的 cmdlet 或重定向写入这些流。 有关详细信息,请参阅 about_Redirection

PowerShell 支持以下输出流。

Stream# 说明 已引入的版本 写入 Cmdlet
1 Success PowerShell 2.0 Write-Output
2 Error PowerShell 2.0 Write-Error
3 Warning PowerShell 2.0 Write-Warning
4 Verbose PowerShell 2.0 Write-Verbose
5 Debug PowerShell 2.0 Write-Debug
6 Information PowerShell 5.0 Write-Information
N/A Progress PowerShell 2.0 Write-Progress

注意

Progress 不支持重定向。

Success 流

Success 是正常成功结果的默认流。 Write-Output使用 cmdlet 将对象显式写入此流。 此流用于通过 PowerShell 管道传递对象。 该 Success 流连接到本机应用程序的 stdout 流。

Error 流

Error 是错误结果的默认流。 使用 Write-Error cmdlet 显式写入此流。 流 Error 连接到本机应用程序的 stderr 流。 在大多数情况下,这些错误可能会终止执行管道。 Error写入此流的 也会添加到 $Error 自动变量。 有关详细信息,请参阅 about_Automatic_Variables

Warning 流

Warning 流适用于比写入 Error 到流的错误更严重的错误条件。 在正常情况下,这些警告不会终止执行。 Warning不会写入 $Error 自动变量。 使用 Write-Warning cmdlet 显式写入此流。

Verbose 流

Verbose 适用于可帮助用户在以交互方式或从脚本中运行命令时对命令进行故障排除的消息。 使用 Write-Verbose cmdlet 将消息显式写入此流。 许多 cmdlet 提供详细的输出,有助于了解 cmdlet 的内部工作。 仅当使用通用参数时, -Verbose 才会输出详细消息。 有关详细信息,请参阅 about_CommonParameters

Debug 流

Debug 用于帮助脚本编写者了解其代码失败的原因的消息。 使用 Write-Debug cmdlet 显式写入此流。 仅当使用通用参数时, -Debug 才会输出调试消息。 有关详细信息,请参阅 about_CommonParameters

Debug 消息适用于脚本和 cmdlet 开发人员,而不是最终用户。 这些调试消息可能包含深入故障排除所需的内部详细信息。

Information 流

Information 流旨在提供可帮助用户了解脚本正在执行的操作的消息。 开发人员还可以将其用作通过 PowerShell 传递信息的其他流。 开发人员可以标记流数据,并针对该流进行特定的处理。 使用 Write-Information cmdlet 显式写入此流。

Write-Host 还会写入 Information 流。 cmdlet 之间的区别在于,除非重定向Information流,Write-Host否则也会写入主机控制台。 Write-Information 仅写入 Information 流。

Progress 流

Progress 用于在运行时间较长的命令和脚本中传达进度的消息。 使用 Write-Progress cmdlet 将消息显式写入此流。 流 Progress 不支持重定向。

另请参阅