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
Tee object can now store received error records to a variable. #21565
base: master
Are you sure you want to change the base?
Tee object can now store received error records to a variable. #21565
Conversation
Tee object can now store error records to a variable.
test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1
Show resolved
Hide resolved
Add a native executable test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
From the example, you seem to have eaten the error!? Tee-Object should still pass through errors, surely. |
} | ||
|
||
It "Positive File/ErrorRecordVariable Test" { | ||
$results = Get-Item $PSHOME,doesnotexist1,$PWD,doesnotexist2 2>&1 | Tee-Object -File $tempFile -ErrorRecordVariable errVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test where you Tee a second time to prove the error still passes through and is output?
Incidentally, is it even possible to get output in I mean, even when I do, say It's weird to me that it has two parameters for output and error variables, but the one we all EXPECT ... does not work. It's pretty confusing. |
If you redirect |
@SteveL-MSFT, while I can appreciate what this PR is trying to achieve, I think it is ultimately the wrong way to go about it, especially given that it requires modifying the call that provides the input (
|
This addresses an aspect of issue #5184
PR Summary
This adds the parameter
-ErrorRecordVariable
(AliasERV
) toTee-Object
if
Tee-Object
receives an ErrorRecord in the input stream and-ErrorRecordVariable
is included,Tee-Object
will assign those error records to the variable. This enables the following scenario:It works with file, literalfile, and variable parameter sets.
This works with native executables as well, as when stderr is written, we create an error record.
Errors created by
Tee-Object
are emitted in the normal way, it is only the input object which is inspected and handled by this new behavior.Note: the
2>&1
is required to ensure that the error stream is emitted into the output streamPR Context
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.(which runs in a different PS Host).