Just redirect the output to nul
.
findstr "test" file.txt >nul
if not errorlevel 1 ( echo Found it!)
문제
I'm new to windows batch scripts but have started using the findstr
command e.g.
findstr "test" file.txt
if not errorlevel 1 ( echo Found it!)
The code manages to findtest
in file.txt
but I don't want it to output the line where it finds "test" I just want it to echo Found it!
Is this possible with findstr
or should I be using something else?
해결책
Just redirect the output to nul
.
findstr "test" file.txt >nul
if not errorlevel 1 ( echo Found it!)
다른 팁
Bali C got the redirection correct, but the OP's original logic was incorrect. Any of the following will work.
findstr "test" file.txt >nul
if not errorlevel 1 (echo Found it!)
or
findstr "test" file.txt >nul
if %errorlevel%==0 (echo Found it!)
or my personal favorite
findstr "test" file.txt >nul && (echo Found it!)