You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PowerShell commands run to completion even with a broken pipe to an external (native) program #8420
Note: The issue isn't specific to Unix, as originally stated - see #15329
... | Select-Object -First 1 stops the upstream command after receiving the 1st input object, but the same is not true when the sink is an external program:
Steps to reproduce
1..10|Write-Output-ov result | head -n 1; $result.Count
Expected behavior
1
1
Actual behavior
1
10
That is, Write-Output unexpectedly ran to completion, even though head exited after receiving the first input line, making it pointless to send additional objects to the pipeline.
Environment data
PowerShell Core v6.2.0-preview.2 on macOS 10.14.1
PowerShell Core v6.2.0-preview.2 on Ubuntu 18.04.1 LTS
In this case, Select-Object manipulating the pipeline to make this happen. I'm not sure if an external program would be able to do the same. In the current implementation it looks like it would be up to the external program to handle this.
Ilya (@iSazonov): head is designed to exit once it has received enough input; doing so leaves the pipe broken, and when the process on the writing end tries to write to the pipe the next time, it normally receives a SIGPIPEsignal, or, if SIGPIPE is unexpectedly ignored (see #8421 ), the system call returns error codeEPIPE.
Kevin Marquette (@KevinMarquette): Yes, as you say,Select-Object uses internal class StopUpstreamCommandsException to stop upstream cmdlets, and, as an aside, it would be nice for user code to have that ability too - see #3821 and #6070.
In the case at hand, however, it would have to be PowerShell that does the SIGPIPE / EPIPE detection and translates it into PowerShell-appropriate termination of the upstream commands.
I haven't looked into the implementation side of things yet.
changed the title [-]PowerShell commands run to completion even with a broken pipe to an external program on Unix-like platforms[/-][+]PowerShell commands run to completion even with a broken pipe to an external (native) program[/+]on Nov 8, 2021
microsoft-github-policy-service commented on Nov 16, 2023
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.
microsoft-github-policy-service commented on Nov 16, 2023
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.
microsoft-github-policy-service commented on Nov 16, 2023
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.
Activity
KevinMarquette commentedon Dec 8, 2018
In this case,
Select-Objectmanipulating the pipeline to make this happen. I'm not sure if an external program would be able to do the same. In the current implementation it looks like it would be up to the external program to handle this.src/Microsoft.PowerShell.Commands.Utility/commands/utility/select-object.cs#L692
iSazonov commentedon Dec 8, 2018
I am not sure that the external command terminates after reading first item. I guess it collects all input. Can we use our TestExe for check?
mklement0 commentedon Dec 8, 2018
Ilya (@iSazonov):
headis designed to exit once it has received enough input; doing so leaves the pipe broken, and when the process on the writing end tries to write to the pipe the next time, it normally receives aSIGPIPEsignal, or, ifSIGPIPEis unexpectedly ignored (see #8421 ), the system call returns error codeEPIPE.Kevin Marquette (@KevinMarquette): Yes, as you say,
Select-Objectuses internal classStopUpstreamCommandsExceptionto stop upstream cmdlets, and, as an aside, it would be nice for user code to have that ability too - see #3821 and #6070.In the case at hand, however, it would have to be PowerShell that does the
SIGPIPE/EPIPEdetection and translates it into PowerShell-appropriate termination of the upstream commands.I haven't looked into the implementation side of things yet.
iSazonov commentedon Dec 8, 2018
Thanks Michael Klement (@mklement0) - I did not read #8421 before commented here.
For reference #2450
[-]PowerShell commands run to completion even with a broken pipe to an external program on Unix-like platforms[/-][+]PowerShell commands run to completion even with a broken pipe to an external (native) program[/+]microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.