背景:測試時須要實時抓取android設備log,可是一份log抓取過來很是龐大(有時超過500M+,編輯器都打不開,還得找工具進行分割,甚是蛋疼),查看也很是不方便。
解決:基於上述狀況,與其以後進行分割,不如採起分段式抓取log方案。文件名以時間命名還很好進行log查看的。
實現:因爲是在win上執行,因此使用批處理實現較爲方便,腳本以下:android
@echo off rem +++++++++++++++++++++++++++++++++++++++++++ rem LogcatLoop.bat rem By zhzw @2018/12/30 rem rem Version: 1.0 rem +++++++++++++++++++++++++++++++++++++++++++ adb wait-for-device rem counter set count=1 set a=1111111 rem Create folder in current path mkdir log >nul :Start echo ---------start %count%--------- set sdate=%date:~0,4%%date:~5,2%%date:~8,2% set stime=%time:~0,2%%time:~3,2%%time:~6,2% if "%stime:~0,1%"==" " set "stime=0%stime:~1%" call :Process if not %a%==000000 set a=000000 & start "logcat-win" /min cmd /c "adb logcat -c & adb logcat -b all>log\%sdate%-%stime%.txt" rem wait 10s to the next loop timeout /t 10 >nul set /a count+=1 if %count%==5 goto Process goto Start :Process rem kill adb logcat process for /f "skip=1 tokens=2" %%i in ('tasklist /nh /fi "WINDOWTITLE eq logcat-win"') do ( set a=%%i taskkill /f /t /pid %%i >nul )