批量测试findstr命令的结果是否为空

3

我希望制作一个批处理程序,可以在文本文件中搜索一行,如果找到该行则返回true,否则返回false。

这是如何查找该行的方法,但我不知道如何进行测试:

findstr /r /c:"^Process Status.*no errors, no warnings$" myfile.log

你能帮我解决这个问题吗?

谢谢


此问题已在相关帖子中得到解答:https://dev59.com/PGsz5IYBdhLWcg3w3r0J?rq=1 - Axel Kemper
这个问题的标题非常误导。 - skeept
1个回答

5
findstr /r /c:"^Process Status.*no errors, no warnings$" myfile.log > nul
if errorlevel 1 (
    echo The line was not found
) else (
    echo The line was found
)

检查命令是否设置了错误级别。如果设置了错误级别,表示未找到文本。


太棒了!那正是我需要的,非常感谢你! - user2269756

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接