[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] [已解决]批处理为多台安卓设备输入不同的内容并打印到一个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!为空时跳出循环
  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
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

本帖最后由 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

TOP

回复 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
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 3# Batcher


    不太行

TOP

回复 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

评分人数

    • dos-a: 乐于助人技术 + 1
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 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

TOP

回复 5# Batcher

感谢大佬!!!

TOP

返回列表