找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19958|回复: 6

[其他] [已解决]批处理为多台安卓设备输入不同的内容并打印到一个txt文本当中

[复制链接]
发表于 2023-2-22 13:51:53 | 显示全部楼层 |阅读模式
本帖最后由 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!为空时跳出循环
  1. setlocal enabledelayedexpansion
  2. for /f "skip=1 tokens=1 delims=        " %%i in ('adb devices') do  (
  3.     set "devices=%%i"
  4.     for /f "delims=, tokens=*" %%r in ('adb  -s !devices! shell getprop ro.product.model') do (
  5.     set "f=%%~nxr"
  6.     set "f=!f: =!"
  7.     set /a "cnt+=1"
  8.     )
  9.         For  /f  "delims="  %%i  in  (2.txt)  do   (
  10.             set "a=%%i"
  11.             adb -s !devices! shell "input text '!a!'"
  12.             echo !a!    %f% >>1.txt
  13.             if "!cnt!"=="" goto 1
  14.     )



  15. )
  16. echo !f!
  17. :1
  18. pause
  19. 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

评分

参与人数 1PB +2 收起 理由
Batcher + 2 感谢给帖子标题标注[已解决]字样

查看全部评分

 楼主| 发表于 2023-2-22 16:32:34 | 显示全部楼层
本帖最后由 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
发表于 2023-2-22 23:00:43 | 显示全部楼层
回复 1# dos-a
  1. @echo off
  2. cd /d "%~dp0"
  3. setlocal enabledelayedexpansion
  4. for /f "skip=1" %%i in ('adb devices ^| findstr "."') do  (
  5.     (for /f "delims=" %%r in ('adb -s %%i shell getprop ro.product.model') do (
  6.         for /f "delims=" %%x in ("%%r") do (
  7.             set "f=%%x"
  8.         )
  9.         set /p "str="
  10.         echo,!str! !f!
  11.     ))<"2.txt" >"1.txt"
  12. )
  13. pause
复制代码
 楼主| 发表于 2023-2-23 19:55:09 | 显示全部楼层
回复 3# Batcher


    不太行
发表于 2023-2-23 22:36:49 | 显示全部楼层
回复 1# dos-a


test_2.bat
  1. @echo off
  2. cd /d "%~dp0"
  3. setlocal enabledelayedexpansion
  4. set "DevNum=0"
  5. type nul >"1.txt"
  6. for /f "skip=1" %%i in ('adb devices') do  (
  7.     echo %%i
  8.     set /a DevNum+=1
  9.     for /f "delims=" %%r in ('adb -s %%i shell getprop ro.product.model') do (
  10.         for /f "delims=" %%x in ("%%r") do (
  11.             set "f=%%x"
  12.         )
  13.     )
  14.     for /f "tokens=1* delims=:" %%a in ('type "2.txt" ^| findstr /n "."') do  (
  15.         if "%%a" equ "!DevNum!" (
  16.             set "str=%%b"
  17.         )
  18.     )
  19.     >>"1.txt" echo,!str! !f!
  20. )
  21. pause
复制代码

评分

参与人数 1技术 +1 收起 理由
dos-a + 1 乐于助人

查看全部评分

 楼主| 发表于 2023-2-25 12:02:37 | 显示全部楼层
本帖最后由 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
 楼主| 发表于 2023-2-25 12:04:25 | 显示全部楼层
回复 5# Batcher

感谢大佬!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 05:25 , Processed in 0.019058 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表