批处理检测执行结果并返回成功或失败 |
您所在的位置:网站首页 › bat保存命令执行结果怎么看 › 批处理检测执行结果并返回成功或失败 |
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 :endfindstr 查找包含 “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" ) )
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |