2013-07-04 29 views
0

我想搜索日志文件中的文本。
如果找到显示错误和文本。
否则显示Not Found and Text。批处理脚本在.log文件中搜索带空格的文本

set str2=Testing Failed in env 
findstr "%str2%" SystemOut.log >nul 
if not errorlevel 1 (echo     ERROR: Testing Failed in env) 
if errorlevel 1 (echo Not Found        Testing Failed in env!) 

无论何时遇到它的日志文件测试它说错误,但它不应该这样做。 当我尝试通过添加引号或其他内容进行更改时肯定条件已通过,但对于否定条件失败。

请帮助我的脚本。

感谢,
Machpatel

回答

1

你需要/ C:切换到包括在文字模式的空间。

@echo off 
set str2=Testing Failed in env 
findstr /c:"%str2%" SystemOut.log >nul 
if errorlevel 1 (echo Not Found  "%str2%") 
if not errorlevel 1 (echo found "%str2%") 
相关问题