Skip to content

$PSNativeCommandUseErrorActionPreference does not work when error stream is discarded #27543

Description

@sharpchen

Prerequisites

Steps to reproduce

I don't see documentation describe this behavior? The doc only mentioned exit code.

& {
    $ErrorActionPreference = 'Continue'
    $PSNativeCommandUseErrorActionPreference = $true

    # expected error:
    robocopy 1>$null # NativeCommandExitException: Program "Robocopy.exe" ended with non-zero exit code: 16 (0x00000010).

    # error discarded:
    robocopy 1>$null 2>$null # no error
    robocopy 1>$null 2>&1 # effectively discarded, so no error

    # not discarded
    robocopy 2>&1 # NativeCommandExitException: Program "Robocopy.exe" ended with non-zero exit code: 16 (0x00000010).
}

Expected behavior

Only exit code matters for the action

Actual behavior

err stream affects the action

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.2
PSEdition                      Core
GitCommitId                    7.6.2
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions