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
Select-Object -First X skips End{ } blocks of previous cmdlets #7930
Comments
Certainly, @BrucePay but given that output from There may also be logging steps or any number of actions that one would expect to be performed in the The worst part is, because this is implemented in this fashion, there is absolutely no way for a module author to combat this. Appreciate the linked issue, but I think that given the pipeline standard of executing |
|
Sure, in cases of error, not everything happens. But Select-Object abusing that means that any sane user who utilises that (awfully handy) functionality remains unaware that code has been skipped -- until something else goes wrong further down the line. In cases of error, this behaviour is relatively obvious. In Select-Object's usage? It's not an error state, it's a deliberately induced state that has unforeseeable consequences unless one is familiar with the underlying code, and shouldn't directly alter other functions' code paths like this. |
I agree that from an end user's perspective there's a crucial difference between something It just so happens that the way |
This issue would be alleviated somewhat with the introduction of |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
2 similar comments
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Using the
-First $n
parameter forSelect-Object
completely skips theend {}
blocks of all cmdlets preceding it in the pipeline.This can be quite hazardous, e.g., for a cmdlet that access a resource that needs to have that handle properly disposed of (like a file) may not release that handle correctly.
There is no
finally {}
block available to PS, and the method in whichSelect-Object
terminates the pipeline appears to happen in such a manner that no script-based function can account for; that is, even with atry...finally
construct in the cmdlets'process {}
blocks it will not kick off in the event thatSelect-Object
is used to prematurely end the pipeline.Instead, a method should be exposed for
Select-Object
(and potentially other cmdlets?) to safely terminate the pipeline by ceasing allprocess
steps and kicking off the chain ofend {}
steps in the pipeline.Steps to reproduce
(shamelessly pinched from @TimCurwick's fantastic example he posted in the PS Slack)
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: