我正在测试我拥有的一些小脚本。这个特别的让我发疯。在我看来,它应该可以工作,但它并没有按照我的想法/应该做。
@echo off
echo testing the issue
echo.
ECHO Checking the log file for errors...
echo %errorlevel%
FINDSTR /C:"open failed" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else (GOTO TSTErrChecking1)
:TSTErrChecking1
FINDSTR /C:"does not exist" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else (GOTO TSTErrChecking2)
:TSTErrChecking2
FINDSTR /C:"Logon failed" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else ( GOTO TSTErrChecking3)
:TSTErrChecking3
FINDSTR /C:"Failure" C:\automatic_deployment\test1.txt
echo %errorlevel%
if %errorlevel% == 0 (
ECHO Deployment failed.
pause
GOTO quit) else ( GOTO TSTErrChecking4)
:TSTErrChecking4
FINDSTR /C:"RC (return code) = 0" C:\automatic_deployment\test1.txt
echo %errorlevel%
IF %ERRORLEVEL% == 0 (
ECHO Deployment was successful.
pause
GOTO quit) ELSE (
ECHO Deployment failed.
pause
GOTO quit)
:quit
exit
如您所见,我正在使用“FINDSTR”从一个小的 test1.txt 文件中查找某些单词/字符串并采取相应的行动。如果它看到任何“失败”/“不存在”/“打开失败”,我希望它说“部署失败”并尽快退出。如果它找不到上述任何一个并找到“RC(返回码)= 0”,我希望它说它是“成功的”。
因此,我将所有这些测试单词和字符串放在我的 test1.txt 文件中并测试了批处理脚本,但它一直跳过(我认为)所有那些失败提示/单词并一直说它是成功的。请帮忙。提前致谢。