2013-11-22 101 views
1

嗨,我試圖找到一個文本文件中的字符串如下的批處理:Windows批處理文件FINDSTRING不起作用

@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 ! 

感謝

馬里亞諾

回答

0

嘗試這種情況:

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

好了,現在可以使用了,謝謝! – Mariano

0

的另一種方法是這樣的:

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

如果findstr發現的&&後的命令將只運行串。

+0

這種方法可以用'set'IF =「'和'set」THEN = &&「'輔助變量以這種方式更清晰地寫入:'%IF%findstr/m/c:」失敗:0「 result.txt%THEN%echo發現它!' – Aacini

+0

這很聰明,但我認爲在比OP提供的腳本更大的腳本中,這會變得更加混淆且容易出錯。 – Mark