Windows批处理文件findstring不起作用

时间:2013-11-22 15:33:38

标签: batch-file findstr

您好我正在尝试使用以下批次在文本文件中查找字符串:

@echo on
findstr /m "Failures: 0"  result.txt
if %errorlevel%==0 (
echo The test is good !
)else (
echo The test is fail !
)

其中result.txt类似于

SGHDSAKGHADGFNA
dfjhytdjkyd
gfhjdgkgl
Failures: 1 Skip: 0
werthjrsh

SGHDSAKGHADGFNA
dfjhytdjkyd
gfhjdgkgl
Failures: 0 Skip: 0
werthjrsh

....

但在两种情况下结果都是

The test is fail !

感谢

马里亚诺

2 个答案:

答案 0 :(得分:0)

试试这个:

findstr /m /c:"Failures: 0" result.txt
if not errorlevel 1 (echo "Found it!") else echo "not found!"

答案 1 :(得分:0)

另一种方法是:

findstr /m /c:"Failures: 0" result.txt && echo Found it!

&&之后的命令只有在findstr找到字符串时才会运行。