Writing SomeCommand | { ... }prints all the output SomeCommandto the code in braces. Is there a way to "lay out" one line at a time and let the code in curly brackets process it line by line, without waiting for all the output to be stored in memory?
SomeCommand | { ... }
SomeCommand
Update
[Copied from comment]
SomeCommandis an executable file (not the powershell cmdlet) that produces some output at run time. It takes some time between the lines that it creates, and I don’t want to wait until all the lines are created to do some operation on each line
script , : :
1, 2, 3 | & { process { $_ Start-Sleep -Seconds 1 } } 1, 2, 3 | & { $input Start-Sleep -Seconds 1 }
, Foreach-Object ( ) , script , , script, script - , ...
Foreach-Object
powershell .
, , , , , . , ( ) . .
Technet
. (, Sort-Object) , .
Sort-Object
ForEach-Object ( %) $_, :
%
$_
Get-ChildItem $pshome | ForEach-Object -Process {if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; "" }}
, , . - , powershell. System.Diagnostics.Process, Process.BeginOutputReadLine, Process.OutputDataReceived , . . .
System.Diagnostics.Process
Process.OutputDataReceived
, . Process.OutputDataReceived.
Output from a text stream (old-style) executed using the PowerShell cmdlet foreach:
foreach
ping.exe www.somesite.com | %{$_}
Explanation: It %is an alias for Foreach-Object. It splits the text stream into newlines and emits lines one by one. In fact, most cmdlets that take strings as input will only work on the command line (this is actually PowerShell, which cuts the text stream, not the cmdlets).
Source: https://habr.com/ru/post/1541948/More articles:How to use iDangerous Swiper and jquery.click (); at the same time - jqueryPHPUnit - не сбой, когда dataProvider возвращает пустой массив - phpunitCombining an element with the next in the list if the condition is met - scalaHow to pass some (but not all) additional arguments using "..." - rHow to properly update a div using jQuery / Ajax in a django template - javascriptThe difference between the new line (char []) and char []. ToString - javaHow to use custom assembly from dojo in file: /// (Cordova / Phonegap) - requirejsScanner Repeat Error - javaRequest.Files the same file downloaded by asp.net mvc - c #Items in a ListBox are displayed as the class name - c #All Articles