0

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
  • What happens when you pipe it directly to Select-String? gunzip.exe -c "_2015-06-05_*" | Select-String -Pattern '1292681581' | Out-File: ... EDIT: Ooooh you're running this from CMD itself. Right. Commented Mar 3, 2016 at 9:14

1 Answer 1

3
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.

Sign up to request clarification or add additional context in comments.

2 Comments

facepalm, i cannot believe I didn't try this already, only issue is its incredibly slow.
Unfortunately I am trying to get rid of a scripts winGrep reliance in a Powershell script so I can add multi-tasking functionality so doing this in powershell in a must.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.