How to force `findstr` to ignore `Cannot open` returns
Asked Answered
G

1

5

I'm trying to use findstr to search inside a folder looking for some string:

findstr /spin /c:"string" *

however it returns back with a lot of Cannot open errors which make it difficult for me to find the exact matches found.

When using Cmder command:

grep -r "string" .

I got Permission denied error for the same folders. If I use the command:

grep -rs "string" .

it gives me the results nice and clean. Is there a similar flag for findstr or a combination of cmd commands to do the same?

there are already some posts for findstr Cannot open error, explaining what is wrong and how to solve it, but I don't care why it is happening. I just want the command to ignore the Cannot open lines and prints out just the lines with exact matches.

Glycolysis answered 30/1, 2018 at 23:32 Comment(0)
R
8

You can make use of 2>nul:

FINDSTR /SPIN /C:"string" * 2>nul

This will pipe the standard-error stream to null (read more), thus only matches are displayed.

Rhodonite answered 31/1, 2018 at 0:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.