Open JamesWTruher opened 2 weeks ago
From the example, you seem to have eaten the error!?
Tee-Object should still pass through errors, surely.
Incidentally, is it even possible to get output in -OutVariable
or -ErrorVariable
from this command?
I mean, even when I do, say | Tee-Object -File Variable:\Foo
or | Tee -File NoSuchDrive:\log.txt
I do not get an error.
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.
Incidentally, is it even possible to get output in
-OutVariable
or-ErrorVariable
from this command?I mean, even when I do, say
| Tee-Object -File Variable:\Foo
or| Tee -File NoSuchDrive:\log.txt
I do not get an error.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 stderr
to stdout
and pipe to Tee-Object
, you'll get both into the output stream and can do whatever you want. We thought the ask was to be able to handle stderr
separately thus the new variable to de-multiplex it. Certainly you could do this yourself just by looking at the type of object and this was a convenience feature.
@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 (2>&1
) in order to work meaningfully.
>
and >>
work, but it is currently limited to consuming the targeted stream; that is, unlike with the common -*Variable
parameters, the stream isn't passed through.Extending the 2> variable:foo
syntax to optionally support pass-through - which you yourself suggested and as previously discussed, where I floated the idea of 2>| variable:foo
- strikes me as the better alternative to extending Tee-Object
.
This addresses an aspect of issue #5184
PR Summary
This adds the parameter
-ErrorRecordVariable
(AliasERV
) toTee-Object
ifTee-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: the2>&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.