为什么 Powershell 的Write-Error
cmdlet 不适合我?我的输出看起来不像文档中的示例:
PS C:\> Write-Error "This is an error"
Write-Error "This is an error" : This is an error
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
我一直期望输出类似于Write-Warning
:
PS H:\> Write-Warning "This is a warning"
WARNING: This is a warning
从Write-Error
和about_preference_variables
文档中,我认为我不应该看到任何异常?
PS H:\> Get-Help About_Preference_Variables
$ErrorActionPreference
----------------------
...
PS> $erroractionpreference
Continue # Display the value of the preference.
PS> write-error "Hello, World"
# Generate a non-terminating error.
write-error "Hello, World" : Hello, World
# The error message is displayed and
execution continues.
PS> write-error "Hello, World" -ErrorAction:SilentlyContinue
# Use the ErrorAction parameter with a
value of "SilentlyContinue".
PS>
# The error message is not displayed and
execution continues.