-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Change $ErrorActionPreference
to not affect stderr output
#13361
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
Conversation
test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1
Outdated
Show resolved
Hide resolved
CodeFactor is an existing issue complaining about the complexity of the method that was updated. Not going to change in this PR. |
Can the stderr ErrorRecords still be captured with |
@felixfbecker No it cannot be captured by |
Basically my question is: How can a user still run a native command, get the stdout output if it was successful, but also get access to the stderr output if it was unsuccessful? That's a very important use case. |
I'm curious how this is done today in console before this PR? In console, unless we redirect the stderr stream, the message written to stderr from the native command will always handled by the console (print on console).
The discussion on it so far is that the exception only has the exit code, not the content from stderr. |
🎉 Handy links: |
PR Summary
Based on @PowerShell/powershell-committee discussion, we agreed that stderr should not be treated as an
ErrorRecord
as many native commands use that as an alternate stream from stdout and it does not signify an error (like verbose or progress information). Stderr output is still wrapped as ErrorRecords, but the runtime no longer applies$ErrorActionPreference
if the ErrorRecord comes from a native command. The diff makes the change look bigger than it is, but it's simply wrapping existing code that applies$ErrorActionPreference
and writing to$Error
to not apply if the ErrorRecord is simply wrapping stderr.Updated
TestExe
to have a switch to write output to stderr.PR Context
Fix #3996
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.PSNotApplyErrorActionToStderr
$ErrorActionPreference
doesn't affect stderr output for native commands MicrosoftDocs/PowerShell-Docs#6466