Stream CMD output to Select-String

☆樱花仙子☆ 提交于 2019-12-12 03:32:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!