bat脚本循环adb命令10次
时间: 2023-10-12 18:09:06 浏览: 277
可以使用 for 循环来执行 adb 命令10次的 bat 脚本,脚本如下:
```
@echo off
setlocal EnableDelayedExpansion
for /l %%i in (1,1,10) do (
echo 这是第 %%i 次执行 adb 命令。
adb shell [你要执行的命令]
)
echo 执行完毕。
pause
```
其中,`adb shell [你要执行的命令]` 中的 `[你要执行的命令]` 改为你要执行的具体命令即可。执行完毕后,脚本会输出“执行完毕。”并等待用户按下任意键结束脚本。
相关问题
bat脚本等待adb connect命令执行失败,再goto去执行其他命令
您可以使用一个while循环来等待adb connect命令执行失败,然后再执行其他命令。示例代码如下:
```
:wait_for_disconnect
adb connect <device_ip>
if %errorlevel%==1 (
goto continue_execution
) else (
timeout /t 5
goto wait_for_disconnect
)
:continue_execution
rem 执行其他命令
```
这段代码会不断执行`adb connect`命令,直到它返回错误码1为止(说明连接失败)。然后会等待5秒钟,然后再次尝试连接。一旦连接成功,就会跳转到`continue_execution`标签,继续执行其他命令。
写一个bat脚本 使其 间隔0.5s无线循环使用 adb shell 命令点击坐标 x:1504 y:666
为了编写一个.bat脚本,使用adb shell命令每0.5秒点击指定的屏幕坐标x:1504 y:666,你需要结合Python的time模块(因为直接在批处理中无法实现定时任务),并且使用adb工具。首先安装adb并确保它在系统的PATH中可用。以下是一个简单的步骤:
1. 首先创建一个名为`clicker.py`的Python脚本,内容如下:
```python
import time
import subprocess
def click_at_coordinate(x, y):
command = f"adb shell input tap {x} {y}"
subprocess.Popen(command, shell=True)
while True:
click_at_coordinate(1504, 666)
time.sleep(0.5) # 每0.5秒执行一次点击
```
2. 然后,在Windows上,你可以通过CMD或者PowerShell运行这个Python脚本。假设Python已安装,可以这样做:
- 使用cmd:
```
python clicker.py
```
- 或者使用PowerShell:
```
powershell python clicker.py
```
3. 当你想停止脚本时,只需关闭Python进程即可,因为它会一直循环执行,除非手动停止。
注意:这个脚本需要计算机连接到Android设备,并且adb已经配置好。如果你的设备未解锁,adb可能无法点击,还需要相应的权限。
阅读全文
相关推荐

















