问题
Is there a way to fluidly stream CMD standard output to PowerShell to Select-String?
I have tried every method I can find, but every way I find stores the info in a variable before piping it to be worked with. It has to be a stream because the standard out can be well over 20GBs in size and ends up causing an out of memory exception before the process crashes.
Here is the command I have been using:
gunzip.exe -c "*_2015-06-05_*" |powershell.exe "& {$input | select-string -pattern '1292681581' | Out-File C:\Users\xadministrator\desktop\test2.txt -append}"
回答1:
powershell.exe "& {gunzip.exe -c '*_2015-06-05_*' | select-string ...}"
You should also be able to do this entirely in CMD (using find or findstr for the filtering) if you find PowerShell too slow:
gunzip.exe -c "*_2015-06-05_*" | find "1292681581" >> "C:\Users\xadministrator\desktop\test2.txt"
However, processing 20 GB of data is going to take some time either way.
来源:https://stackoverflow.com/questions/35766692/stream-cmd-output-to-select-string