我想编写Windows批处理脚本以从输出文件中查找错误消息。
我已经编写了一些示例代码来创建输出文件并搜索ERROR MESSAGE“ERROR”。
@eacho on
pdm_webstat >> pdm_webstat.txt
find /c "ERROR" pdm_webstat.txt
pdm_webstat
的输出如下:
PDM_Webstat: Invoked at 08/20/2013 13:01:56
=========================================
Report from Webengine: web:wsp
=========================================
Cumulative sessions so far = 0
Most sessions at a time = 0
Currently active sessions = 0
=========================================
Report from Webengine: web:local
=========================================
ERROR : web engine failed to run
现在我在输出文件中搜索字符串ERROR
,如下所示:
find /c "ERROR" pdm_webstat.txt
如果找到错误消息,我必须运行一些语句。
任何人都可以帮我编写上述要求的脚本吗?
答案 0 :(得分:3)
你可以试试这个:
find /i "ERROR" pdm_webstat.txt >nul 2>&1 && (
echo "ERROR" found
REM run your Java program here
) || (
echo "ERROR" not found
REM command if "ERROR" not found
)