Это то, что я сделал, чтобы сделать скринкап на нескольких неопределенных устройствах;
@echo off
setlocal enableDelayedExpansion
REM Some Variables To Create Directories with
set VERSION=APPVERSION
set TEST=TESTNAME
REM used to remove 'device' from each line
set "replace=device"
set "replaced="
set "source=test.txt"
set "target=clean.txt"
REM adb command to grab all connected devices
adb devices > adb.txt
REM Used to generate a filename friendly datetime
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%
REM Strip everything except the device ID/Serial Number
findstr /v "List of devices attached" adb.txt > test.txt
(
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
set "line=%%b"
if defined line set "line=!line:%replace%=%replaced%!"
echo(!line!)
) > %target%
REM with the 'clean' file of just device IDs, set them as elements of an array
set idi=0
for /F "usebackq" %%A in (clean.txt) do (
SET /A idi=!idi! + 1
set var!idi!=%%A
)
set var
REM now the true work can begin
REM we use the device ids to take and save a screenshot from each device
REM we are putting the screenshots into a device specific folder in VERSION\TEST directory
REM the screenshot name is formatted as 'deviceID-datetime.ping'
for /L %%x in (1, 1, %idi%) do (
if not exist "%UserProfile%\Desktop\%VERSION%\%TEST%\!var%%x!" mkdir %UserProfile%\Desktop\%VERSION%\%TEST%\!var%%x!
adb -s !var%%x! shell screencap -p /sdcard/!var%%x!-%datetime%.png
adb -s !var%%x! pull /sdcard/!var%%x!-%datetime%.png %UserProfile%\Desktop\%VERSION%\%TEST%\!var%%x!
adb -s !var%%x! shell rm /sdcard/!var%%x!-%datetime%.png
)
Часть вы, вероятно, больше всего волнует та часть, которая идентифицирует вас все подключенные устройства серийные номера, чтобы использовать команду, которую вы хотите выполнить на каждом устройстве;
REM used to remove 'device' from each line
set "replace=device"
set "replaced="
set "source=test.txt"
set "target=clean.txt"
REM adb command to grab all connected devices
adb devices > adb.txt
findstr /v "List of devices attached" adb.txt > test.txt
(
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
set "line=%%b"
if defined line set "line=!line:%replace%=%replaced%!"
echo(!line!)
) > %target%
REM with the 'clean' file of just device IDs, set them as elements of an array
set idi=0
for /F "usebackq" %%A in (clean.txt) do (
SET /A idi=!idi! + 1
set var!idi!=%%A
)
set var
Оттуда вы можете просто изменить последний бит, чтобы включить свою команду;
for /L %%x in (1, 1, %idi%) do (
adb -s !var%%x! shell <command>)
Возможно, существует «более чистый» способ, но это работает для моих целей.