背景:window电脑抓日志时,每次需要手敲adb命令【adb logcat>本地目录.log】,比较麻烦
使用shell去改成bat工具,执行adb命令,一键抓日志、截图、截屏等 、
步骤:
1. 新建一个空白的txt文件
2. 复制shell脚本进去,然后把txt文件后缀改为bat
抓日志 logcat.bat:
adb logcat -c
adb shell logcat -v threadtime >C:\Users\wh\Desktop\tools\logs\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%_%time:~6,2%.log
adb push C:\Users\wh\Desktop\tools\logs\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%_%time:~6,2%.log /mnt/sdcard/
@echo off
if exist w:\ (
subst w: /d
) else if exist v:\ (
subst v: /d
截图:
if %time:~0,2% leq 9 (set hour=0%time:~1,1%) else (set hour=%time:~0,2%)
set fileName=/sdcard/%date:~0,4%%date:~5,2%%date:~8,2%_%hour%%time:~3,2%_%time:~6,2%.png
adb shell screencap -p %fileName%
adb pull %fileName% C:\Users\wanghang\Desktop\tools\logs
adb shell rm %fileName%
使用adb录屏:
@ECHO OFF
CLS
color 0a
set SCREEN_RECORD_SAVE_DIR=/sdcard/screenrecord
set SCREEN_RECORD_NAME=screenrecord.mp4
set SCREEN_RECORD_WIN_SAVE_DIR=screenrecord
set SCREEN_CAPTURE_SAVE_DIR=/sdcard/screencap
set SCREEN_CAPTURE_NAME=screencap.png
set SCREEN_CAPTURE_WIN_SAVE_DIR=screencap
REM when hour bit < 10,should if check
set NOW_TIME_HH=%time:~0,2%
if "%NOW_TIME_HH%" lss "10" (set NOW_TIME_HH=0%time:~1,1%) else (set NOW_TIME_HH=%time:~0,2%)
set NOW_TIME=%date:~0,4%%date:~5,2%%date:~8,2%%NOW_TIME_HH%%time:~3,2%%time:~6,2%
GOTO MENU
:MENU
ECHO.
ECHO. Android Screen MP4 Record
ECHO.
ECHO. 1 Record MP4
ECHO.
ECHO. 2 Pull MP4 file
ECHO.
ECHO. 3 Screen capture
ECHO.
ECHO. 4 Exit
ECHO.
ECHO.
REM echo. pls choose number:
set /p id= Pls choose number:
if "%id%"=="1" goto cmd1
if "%id%"=="2" goto cmd2
if "%id%"=="3" goto cmd3
IF "%id%"=="4" exit ELSE (
echo Enter number %id% is not recognited,pls enter again!
pause
GOTO MENU
)
@REM Recording MP4
:cmd1
echo Recording MP4,pls waiting...
ECHO.
adb shell rm -rf %SCREEN_RECORD_SAVE_DIR%
adb shell mkdir -p %SCREEN_RECORD_SAVE_DIR%
adb shell screenrecord --bit-rate 4000000 --size 1920x1080 %SCREEN_RECORD_SAVE_DIR%/%SCREEN_RECORD_NAME%
GOTO PUASE
@REM Pull MP4 file
:cmd2
echo Pulling MP4 file,pls waiting...
ECHO.
REM rd /S /Q %SCREEN_RECORD_WIN_SAVE_DIR%
if not exist %SCREEN_RECORD_WIN_SAVE_DIR% mkdir %SCREEN_RECORD_WIN_SAVE_DIR%
adb pull %SCREEN_RECORD_SAVE_DIR%/%SCREEN_RECORD_NAME% %SCREEN_RECORD_WIN_SAVE_DIR%
cd %SCREEN_RECORD_WIN_SAVE_DIR%
REM for MP4 file add time stamp
ren %SCREEN_RECORD_NAME% %NOW_TIME%%SCREEN_RECORD_NAME%
ECHO.
echo %SCREEN_RECORD_NAME% file has pulled!!
ECHO.
GOTO PUASE
@REM Screen capture
:cmd3
echo Doing screen capture,pls waiting...
ECHO.
adb shell rm -rf %SCREEN_CAPTURE_SAVE_DIR%
adb shell mkdir -p %SCREEN_CAPTURE_SAVE_DIR%
adb shell screencap -p %SCREEN_CAPTURE_SAVE_DIR%/%SCREEN_CAPTURE_NAME%
if not exist %SCREEN_CAPTURE_WIN_SAVE_DIR% mkdir %SCREEN_CAPTURE_WIN_SAVE_DIR%
adb pull %SCREEN_CAPTURE_SAVE_DIR%/%SCREEN_CAPTURE_NAME% %SCREEN_CAPTURE_WIN_SAVE_DIR%
cd %SCREEN_CAPTURE_WIN_SAVE_DIR%
REM for png file add time stamp
ren %SCREEN_CAPTURE_NAME% %NOW_TIME%%SCREEN_CAPTURE_NAME%
ECHO.
echo %SCREEN_CAPTURE_NAME% file has pulled!!
ECHO.
GOTO PUASE
:PUASE
pause
echo.
最终效果演示:
1. 抓日志
鼠标左键双击 log.bat
当前目录下 ,生成日志文件,并按年月日时分秒命名