批处理检测执行结果并返回成功或失败

result.txt 文件中写入了执行结果(文本),如果文件文本包含failed,则认为执行失败;否则认为执行成功。

@echo off
REM ********Result Check********
REM First Edit 2019

set TargetPath=E:\jenkins\workspace\Smoke

set target_stresult=%TargetPath%\result.txt

set target_st_result=%TargetPath%\ST_result.txt

if exist %target_st_result% del %target_st_result%

findstr "failed" %target_stresult% >%target_st_result%


if errorlevel 1 goto succ
if errorlevel 0 goto fail

:fail
exit 1
goto end

:succ
cd %TargetPath%
goto end

:end

findstr  查找包含 “failed” 的行

errorlevel:

0复制文件成功 
1 未找到复制文件 
2 用户通过CTRL C 终止了xcopy操作 
4 出现了初始化错误  
5 出现了磁盘写入错误

扩展一则:

set  JenkinsPath=C:\CI_MMESGSN\jenkins\workspace\ST

qprocess | findstr "nginx.exe"
if %errorlevel% == 0 (
echo nginx server is running, no need to operator
) else (
echo nginx server is not running
cd %JenkinsPath%\nginx-1.11.10\nginx-1.11.10
start nginx
cd %JenkinsPath%
)
tasklist|find /i "nginx.exe">nul
if %errorlevel%==0 (
    if exist "%aaa%\config\user\hahaha.txt" (
        echo %date% %time% >>"%ResultDir%\run.log"
        echo %psttpath% >>"%ResultDir%\run.log"
    )
)
发布了144 篇原创文章 · 获赞 58 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/qqyuanhao163/article/details/103091768
今日推荐