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

Using a 2> error-stream redirection with cmdlets still records error records in $Error #4572

Closed
mklement0 opened this issue Aug 14, 2017 · 2 comments
Labels
Resolution-By Design The reported behavior is by design.

Comments

@mklement0
Copy link
Contributor

Closely related to #4002, which discusses the problem with respect to invoking external utilities, where it has additional side effects.

Any attempt to redirect the error-output stream with 2> causes the errors unexpectedly be recorded in the $Error collection as well.

While this could be considered as designed, it may contravene user expectations, especially with 2>$null.

Steps to reproduce

$Error.Clear(); Get-Item /NoSuch 2>$null; $Error

Expected behavior

No output.

Actual behavior

Get-Item : Cannot find path '/NoSuch' because it does not exist.
...

That is, despite the explicit intent to discard error output, it was recorded in $Error behind the scenes.

Similarly, redirecting to a file exhibits the same behavior.

Environment data

PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
@SteveL-MSFT SteveL-MSFT added the Resolution-By Design The reported behavior is by design. label Aug 14, 2017
@SteveL-MSFT
Copy link
Member

The redirection is independent of the "running $error log". As you know, there's several issues covering terminating/non-terminating, stderr, etc... I'm open to proposals on how to simplify our error handling story while not introducing breaking changes where possible.

@mklement0
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-By Design The reported behavior is by design.
Projects
None yet
Development

No branches or pull requests

2 participants