The Wayback Machine - https://web.archive.org/web/20230813033818/https://github.com/PowerShell/PowerShell/issues/1947
Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

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

Pipe waits for the first command to be finished #1947

Closed
ilius opened this issue Aug 19, 2016 · 5 comments
Closed

Pipe waits for the first command to be finished #1947

ilius opened this issue Aug 19, 2016 · 5 comments
Labels
Resolution-Duplicate The issue is a duplicate.

Comments

@ilius
Copy link

ilius commented Aug 19, 2016

Since there are 281 open issues, I'm not sure if this is reported before or not

Try a command that takes too long (possibly forever) and produces lots of output, and we want to give the output to another command using pipe, for example:

find / -iname '*.exe' | less

PowerShell waits for the first command to be finished, and then runs the second command and give it the whole output. That is not what Unix pipes have been about for decades! We expect the second command to be executed right after we press enter (try sleep 10 | echo test in Bash), and send any output from first command immediately to the second command.

Tested with PowerShell 6.0.0 on Debian GNU/Linux

@kilasuit
Copy link
Collaborator

kilasuit commented Aug 19, 2016

This is a core PowerShell design feature and is not likely to be changed as would be a major breaking change due to the way that the pipeline works and is designed.

an example to understand how the pipeline is used in Powershell would be like

 Get-ChildItem C:\scripts\ -Recurse | Where-Object {$_.Name -like "*.ps*1"} | Group-object -Property Extension | Select-Object Count,Name

To break this down we are getting all the items in the C:\Scripts\ folder and recursive folders and then with the collection of objects that would output we pass this to Where-Object using the Pipeline to then only return files that have a ps*1 extension and then with the collection of objects that would output this is then passed again using the pipeline to Group-Object where we get an output based on the grouping of the items based on the file extension and the we pipe this to Select-Object and tell it that we want only the Count and Name returned from that collection

The Output we would get from would get something similar to the below

Count Name 
----- ---- 
   76 .ps1 
    1 .psm1

Happy to answer any other questions on the PowerShell Pipeline if you have them?

@RamblingCookieMonster
Copy link

RamblingCookieMonster commented Aug 19, 2016

Hi!

@kilasuit, I could be off base, but IIRC commands with a proper process block implementation will stream their output, allowing something akin to @ilius' example.

I'm guessing there might be some odd behavior if you mix and match output from *nix tools and PowerShell tools, and this would be expected in cases where you have a blocking command (e.g. you need all items to sort them).

Cheers!

@KevinMarquette
Copy link
Contributor

@RamblingCookieMonster is correct. Powershell will stream objects down the pipe when it can. A good common example would be to tail a log file and pipe to a search string.

Get-Content -Path $path -Tail | Select-String 'Error'

But there are other commands that will block the pipe and wait for all the objects before continuing. Sort-Object is an obvious example.

@ilius
Copy link
Author

ilius commented Aug 20, 2016

I can't see how this breaks compatibility
If a command (like ``Sort-ObjectorSelect-Object`) needs the whole input to process, it can wait for the whole input itself, that's up to the second command (receiver), that does not prevent the first command (sender) or the Shell to send it's output.

https://en.wikipedia.org/wiki/Pipeline_(Unix)

@lzybkr
Copy link
Member

lzybkr commented Aug 20, 2016

Closing as this is a duplicate, see #559. It is fixable, but a bit tricky.

@lzybkr lzybkr closed this as completed Aug 20, 2016
@lzybkr lzybkr added the Resolution-Duplicate The issue is a duplicate. label Aug 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate The issue is a duplicate.
Projects
None yet
Development

No branches or pull requests

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.