标题: [其他] [已解决]批处理为多台安卓设备输入不同的内容并打印到一个txt文本当中 [打印本页]
作者: dos-a 时间: 2023-2-22 13:51 标题: [已解决]批处理为多台安卓设备输入不同的内容并打印到一个txt文本当中
本帖最后由 dos-a 于 2023-2-25 13:17 编辑
@Batcher 大佬这个如何实现呢?
用for遍历adb devices所获得的序列号 !devices!
然后把遍历所获得的序列号使用字符截断处理一下设置为!f!
在下面写一个for每次遍历一行2.txt内容定义为变量 !a!
在下面使用
adb -s !devices! shell "input text '!a!'"
然后把 !a!每一行 与每次devics 对应追加到新 1.txt内
!devices!为空时跳出循环- setlocal enabledelayedexpansion
- for /f "skip=1 tokens=1 delims= " %%i in ('adb devices') do (
- set "devices=%%i"
- for /f "delims=, tokens=*" %%r in ('adb -s !devices! shell getprop ro.product.model') do (
- set "f=%%~nxr"
- set "f=!f: =!"
- set /a "cnt+=1"
- )
- For /f "delims=" %%i in (2.txt) do (
- set "a=%%i"
- adb -s !devices! shell "input text '!a!'"
- echo !a! %f% >>1.txt
- if "!cnt!"=="" goto 1
- )
-
-
-
- )
- echo !f!
- :1
- pause
- goto 2
复制代码
不知道我这样写为啥会无限追加2.txt内容,序列号也没追加进去1.txt
2.txt内容:
12345678
2468024
345653353
23423545
2345346534
356346456
25345343534
1.txt结果:
12345678
2468024
345653353
23423545
2345346534
356346456
25345343534
12345678
作者: dos-a 时间: 2023-2-22 16:32
本帖最后由 dos-a 于 2023-2-22 16:39 编辑
回复 1# dos-a
修改为:
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1 delims= " %%i in ('adb devices') do (
set "devices=%%i"
for /f "delims=, tokens=*" %%r in ('adb -s !devices! shell getprop ro.product.model') do (
set "f=%%~nxr"
set "f=!f: =!"
set /a "cnt+=1"
)
For /f "delims=" %%i in (2.txt) do (
set "a=%%i"
adb -s !devices! shell "input text '!a!'"
echo !a! !f! >>1.txt
if "!cnt!"=="" goto 1
)
)
echo !f!
:1
pause
goto 2
后打印结果1.txt为:
12345678 SHARKKSR-A0
2468024 SHARKKSR-A0
345653353 SHARKKSR-A0
23423545 SHARKKSR-A0
2345346534 SHARKKSR-A0
356346456 SHARKKSR-A0
25345343534 SHARKKSR-A0
这是单台,如果为两台:
12345678 MI6
2468024 MI6
345653353 MI6
23423545 MI6
2345346534 MI6
356346456 MI6
25345343534 MI6
12345678 SHARKKSR-A0
2468024 SHARKKSR-A0
345653353 SHARKKSR-A0
23423545 SHARKKSR-A0
2345346534 SHARKKSR-A0
356346456 SHARKKSR-A0
25345343534 SHARKKSR-A0
作者: Batcher 时间: 2023-2-22 23:00
回复 1# dos-a - @echo off
- cd /d "%~dp0"
- setlocal enabledelayedexpansion
- for /f "skip=1" %%i in ('adb devices ^| findstr "."') do (
- (for /f "delims=" %%r in ('adb -s %%i shell getprop ro.product.model') do (
- for /f "delims=" %%x in ("%%r") do (
- set "f=%%x"
- )
- set /p "str="
- echo,!str! !f!
- ))<"2.txt" >"1.txt"
- )
- pause
复制代码
作者: dos-a 时间: 2023-2-23 19:55
回复 3# Batcher
不太行
作者: Batcher 时间: 2023-2-23 22:36
回复 1# dos-a
test_2.bat- @echo off
- cd /d "%~dp0"
- setlocal enabledelayedexpansion
- set "DevNum=0"
- type nul >"1.txt"
- for /f "skip=1" %%i in ('adb devices') do (
- echo %%i
- set /a DevNum+=1
- for /f "delims=" %%r in ('adb -s %%i shell getprop ro.product.model') do (
- for /f "delims=" %%x in ("%%r") do (
- set "f=%%x"
- )
- )
- for /f "tokens=1* delims=:" %%a in ('type "2.txt" ^| findstr /n "."') do (
- if "%%a" equ "!DevNum!" (
- set "str=%%b"
- )
- )
- >>"1.txt" echo,!str! !f!
- )
- pause
复制代码
作者: dos-a 时间: 2023-2-25 12:02
本帖最后由 dos-a 于 2023-2-25 12:03 编辑
回复 5# Batcher
我也自己折腾了一样的代码如何下:
@echo off
setlocal enabledelayedexpansion
pause&echo 按任意键开始
echo %time%
for /f "skip=1 tokens=1 delims= " %%i in ('adb devices') do (
set "devices=%%i"
set "f="
if "devices"=="" goto end
for /f "delims=, tokens=*" %%r in ('adb -s !devices! shell getprop ro.product.model') do (
set "f=%%~nxr"
set "f=!f: =!"
set /a g+=1
)
set lineFlag=0
for /f "delims=*" %%i in (1.txt) do (
set /a lineFlag+=1
if !lineFlag!==!g! (
set lineContent=%%i
)
)
echo 正在写入账号(!lineContent!)至,model:【!f!】
adb -s !devices! shell "input text '!lineContent!'"
echo !lineContent! !f! >>2.txt
)
:end
echo %time%
pause
1.txt:
211126282
277102841
342776200
236678671
145424554
305510029
156005168
结果:2.txt:
211126282 TECNOKE7
277102841 TECNOLD7
342776200 TECNOKE5
236678671 InfinixX695
145424554 RedmiNote9ProMax
作者: dos-a 时间: 2023-2-25 12:04
回复 5# Batcher
感谢大佬!!!
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |