Skip to content

$ErrorActionPreference doesn't affect stderr output for native commands #6466

Closed

Description

Summary of the new document or enhancement

The PR PowerShell/PowerShell#13361 made a breaking change that $ErrorActionPreference doesn't affect stderr output for native commands.
Also the error records generated from the stderr output of native commands are not put in $Error and variable specified by -ErrorVariable.

Description of what changed

Activity

  1. SteveL-MSFT commented on Aug 10, 2020

    @SteveL-MSFT
    Contributor

    I think what needs to be said should be a bit more detailed on the user impact even though Dongbo Wang (@daxian-dbw)'s content is technically correct:

    • Previously, when stderr was redirected (like ls foo 2>$null), if the native command wrote to stderr, then it resulted in an ErrorRecord written to $Error. This also meant that $ErrorActionPreference was affected by this ErrorRecord. With PowerShell7.1, we recognized that many native commands write to stderr not as error messages, but an alternate stream for additional information that doesn't make sense to write to stdout. This includes content such as verbose or progress output.
    • I'm also working on a PR that is related to this and should be documented at the same time. Because stderr is no longer a means to indicate a native command has error'd. This means that $? which tells you if the last command succeeded or failed, should indicate succeeded if the native command exit code is 0 despite any content written to stderr.
  2. mklement0 commented on Aug 11, 2020

    @mklement0
    Contributor

    This information should eventually also be incorporated into the proposed conceptual help topic about calling external (native) executables - see #5152.

  3. chasewilson commented on Aug 12, 2020

    @chasewilson
    Contributor

    Just for Record and clarity, as of right now, this is an experimental feature and should be documented as such correct Dongbo Wang (@daxian-dbw) , Steve Lee (@SteveL-MSFT) ?

  4. mklement0 commented on Aug 12, 2020

    @mklement0
    Contributor

    Speaking of, Steve Lee (@SteveL-MSFT):

    Can we consider implementing this as a straight bug fix?

    The current behavior is useless and counterintuitive:

    If I execute ls nosuch 2>$null or ls nosuch 2>err.txt, the intent is clearly to silence / capture all stderr output - and not to abort the command just because $ErrorActionPreference happens to be set to 'Stop' (which without the 2> redirection would have no impact on the command).

  5. added a commit that references this issue on Aug 20, 2020
    9e2dfd4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-aboutArea - About_ topics

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions