mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-23 17:53:58 +08:00
Fix $?
to not be $false
when native command writes to stderr
(#13395)
This commit is contained in:
parent
1a0a5db069
commit
d67649c300
@ -2825,7 +2825,6 @@ namespace System.Management.Automation
|
||||
Severity.Warning);
|
||||
}
|
||||
|
||||
this.PipelineProcessor.ExecutionFailed = true;
|
||||
if (LogPipelineExecutionDetail)
|
||||
{
|
||||
this.PipelineProcessor.LogExecutionError(_thisCommand.MyInvocation, errorRecord);
|
||||
@ -2833,6 +2832,8 @@ namespace System.Management.Automation
|
||||
|
||||
if (!(ExperimentalFeature.IsEnabled("PSNotApplyErrorActionToStderr") && isNativeError))
|
||||
{
|
||||
this.PipelineProcessor.ExecutionFailed = true;
|
||||
|
||||
ActionPreference preference = ErrorAction;
|
||||
if (actionPreference.HasValue)
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ Describe "Native Command Processor" -tags "Feature" {
|
||||
}
|
||||
|
||||
It '$ErrorActionPreference does not apply to redirected stderr output' -Skip:(!$EnabledExperimentalFeatures.Contains('PSNotApplyErrorActionToStderr')) {
|
||||
pwsh -noprofile -command '$ErrorActionPreference = ''Stop''; testexe -stderr stop 2>$null; ''hello''; $error' | Should -BeExactly 'hello'
|
||||
pwsh -noprofile -command '$ErrorActionPreference = ''Stop''; testexe -stderr stop 2>$null; ''hello''; $error; $?' | Should -BeExactly 'hello','True'
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user