Fix $? to not be $false when native command writes to stderr (#13395)

This commit is contained in:
Steve Lee 2020-08-19 09:31:38 -07:00 committed by GitHub
parent 1a0a5db069
commit d67649c300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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)
{

View File

@ -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'
}
}