adb的批处理脚本通过wifi连接

时间:2016-09-27 05:11:31

标签: batch-file adb

我正在尝试编写一个批处理脚本来自动执行某项任务,并根据上一个命令的响应或输出生态查看下一个命令或输出。

adb connect %IP%:5555
 if errorlevel 1 (
      echo Not Able To connect With Provided Ip Address
      goto getip
) else (
    echo Connected Over Wifi
    goto menu2
    )

但它不起作用,因为我认为在每种情况下错误级别为0 设备连接成功与否输出相同“通过wifi连接”。

通常当我们输入命令adb connect <IP>时,输出是

1)连接成功输出

connected to 192.168.10.13:5555

2)当android设备在wifi lan并且输入“ip”是正确但“5555”端口未打开然后输出

unable to connect to 192.168.10.13:5555: cannot connect to 192.168.10.13:5555: No connection could be made because the target machine actively refused it. (10061)

3)当笔记本电脑的wifi关闭时

unable to connect to 192.168.10.13:5555: cannot connect to 192.168.10.13:5555: A socket operation was attempted to an unreachable host. (10065)

4)当android的wifi关闭时

unable to connect to 192.168.10.2:5555: cannot connect to 192.168.10.2:5555: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

我想只定义两个案例"connection Successful" or "Not Successful"

我应该怎么做才能根据adb连接设置自动执行任务。请帮忙

1 个答案:

答案 0 :(得分:0)

您可以将adb的输出传递给FIND并搜索指示成功或失败的指示标记,例如“无法”或“连接到”。

@echo off & setlocal
set IP=192.168.10.13:5555
adb connect %IP% | find /i "connected to" >nul
if errorlevel 1 (
    echo Not successful
) else (
    echo Successful
)