赞
踩
用 usb 线连接电脑,打开 usb 调试,可以看到设备的 serial number
adb devices
首先需要新建一个文件夹,之后新建的文件需要放在同一文件夹
下。
如果不支持 adb 命令,需要先配置 adb 的环境变量。
这里是已经封装好的 adb 批处理工具 adb_tools.zip ,其中 device_list.txt
中需要替换成自己的设备 serial number
device_list.txt
文件存放的是手机的device serial number(设备序列号)
,这个序列号一般是不会变得。
批处理命令自动连接无线调试,是从这个文件中读取设备序列号,循环遍历去尝试连接。
注意里边填自己的设备序列号
10466db3
adb_tools.bat
注意保存时另存为编码格式为 ANSI
的文本,不然中文会乱码
@echo off :main echo please choose execution: echo 1.connect all android devices: echo 2.install APK: echo 0.exit: set /p choose=please input choose: if %choose%==1 goto connect if %choose%==2 goto install if %choose%==0 exit pause :connect @rem 连接 wifi 调试 setlocal enabledelayedexpansion echo 物理设备 serial number 请提前填写在同目录下的 device_list.txt 中 for /f %%h in (%~dp0device_list.txt) do ( echo ------------------------------------------- echo ------------adb connect start------------ echo ------------------------------------------- echo device_serial_number = %%h set command=adb -s %%h shell "ip address | grep inet | grep 192 | grep -v inet6 | grep -v 127" for /F "tokens=*" %%i in ('!command!') do ( set str="%%i" ) for /f "tokens=2,*" %%a in (!str!) do ( set str="%%a" ) echo str = !str! for /f "delims=/ tokens=1,*" %%a in (!str!) do ( set str=%%a ) echo device_ip = !str! adb -s %%h tcpip 5555 set _ip=!str!:5555 set command=adb connect !_ip! for /F "tokens=*" %%i in ('!command!') do ( set RESULT="%%i" ) echo !RESULT! |findstr "connected" >nul if !errorlevel! equ 0 ( echo "wifi adb connect success,device_serial_number : %%h, ip : !_ip!" ) else ( echo "wifi adb connect failed,device_serial_number : %%h, ip : !_ip!" ) echo ---------clear variables in foreach------- set command=0 set str=0 set _ip=0 set RESULT=0 echo ------------------------------------------ echo ------------adb connect end------------ echo ------------------------------------------ echo . echo . echo . ) adb devices endlocal pause goto main :install @rem 安装apk setlocal enabledelayedexpansion echo ------------------------------------------- echo ------------install apk start------------ echo ------------------------------------------- set command=adb devices for /F "tokens=*" %%i in ('!command!') do ( set full_str="%%i" for /f "tokens=2,*" %%j in (!full_str!) do set end_str="%%j" if !end_str! equ "device" ( for /f "tokens=1,*" %%k in (!full_str!) do set start_str=%%k if not defined devices ( set devices=!start_str! ) else ( set devices=!devices!,!start_str! ) ) ) if not defined devices ( echo no device connected!!! goto :end ) echo all connected devices: !devices! set print_devices=!devices:,d= ! set device_number=1 echo choose target device: for %%a in (!print_devices!) do ( echo !device_number!. %%a set /a device_number = !device_number! + 1 ) set /p selected_device_number=input device_number: for /f "delims=, tokens=%selected_device_number%" %%a in ("!devices!") do set device_serial_number=%%a echo choosed device serial number: !device_serial_number! set /p apk_path=input apk_path: if not exist %apk_path% ( echo %apk_path% not exist! ) echo inputed apk_path: %apk_path% adb -s !device_serial_number! install -r -t %apk_path% echo ----------!device_serial_number! install success echo ------------------------------------------ echo ------------install apk end------------ echo ------------------------------------------ echo . echo . echo . :end endlocal pause goto main
bat批处理与adb命令的配合
怎样写一句for语句的批处理,用来把一个字符串分割成一个一个的子字符串
批处理中怎么判断一个参数是否被赋值成功
批处理中for中set的问题
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。