Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
daxian-dbw opened this issue Aug 10, 2020 · 4 comments · Fixed by #6505
Closed

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

daxian-dbw opened this issue Aug 10, 2020 · 4 comments · Fixed by #6505
Assignees
Labels
area-about Area - About_ topics
Milestone

Comments

@daxian-dbw
Copy link
Contributor

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

@daxian-dbw daxian-dbw added the issue-doc-idea Issue - request for new content label Aug 10, 2020
@chasewilson chasewilson self-assigned this Aug 10, 2020
@SteveL-MSFT
Copy link
Contributor

I think what needs to be said should be a bit more detailed on the user impact even though @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.

@mklement0
Copy link
Contributor

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

@chasewilson
Copy link
Contributor

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

@mklement0
Copy link
Contributor

Speaking of, @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).

@sdwheeler sdwheeler added area-about Area - About_ topics and removed issue-doc-idea Issue - request for new content labels Aug 12, 2020
@sdwheeler sdwheeler added this to the 7.1.0 milestone Aug 12, 2020
DCtheGeek pushed a commit that referenced this issue Aug 20, 2020
* This adds information about new ErrorActionPreference behavior in PowerShell 7.1

* Revert "This adds information about new ErrorActionPreference behavior in PowerShell 7.1"

This reverts commit 8b0672d.

* This adds information about new ErrorActionPreference behavior in PowerShell 7.1

* Updates for PR

* PR updates

* Update for PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-about Area - About_ topics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants