提示用户选择设备(从行) [英] Prompt user to select device (from line)

查看:67
本文介绍了提示用户选择设备(从行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出连接的adb设备,并提示用户选择要部署APK的行。

I'm trying to list the connected adb devices and prompt the user to select a line to deploy an APK to.

到目前为止,我已经尝试过:

So far I've tried:

for %%i in (adb devices) do (
    ECHO %%i
)

但这根本行不通。有什么方法可以将每个adb设备的ID捕获到变量中?我的目标是尽可能地捕获每个id,例如:

But that won't work at all. Is there any way to capture the id of each adb device into variables? My goal if possible is to capture each id like:

%line1=f2ea3410

从adb列出 adb设备

f2ea3410        device
f2fa3410        device

所以我可以提示用户 line (而不是很难输入的ID):

So I can prompt the user the line (and not the id which is painful to type):

@ECHO OFF
set /p id="Enter Line:"


推荐答案

I使用您提供的示例对此进行了测试。只需修改:DoIt 即可对可用ID进行任何操作。

I tested this with the example you provided. Just modify :DoIt to do whatever it is you want to do with the available Id.

@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@rem @set prompt=$G

@set _command=adb.cmd
@set _count=0

@for /f "tokens=1,*" %%G in ('%_command% devices') do @call :AddAndDisplayDevice %%G "%%H"
@set /p _choice=Enter number from above menu:
@if not defined _%_choice% @goto :BadSelection "%_choice%"
@call :DoIt %_choice%
@exit /b 0

:AddAndDisplayDevice
@set /a _count+=1
@echo %_count%. %*
@call :SetVar %_count% %1
@call :SetVar %_count%_description %2
@exit /b 0

:BadSelection
@rem Up to you whether to loop back and try again.
@echo Bad choice: %_choice%
@exit /b -1

:DoIt
@set _Id=!_%1!
@rem set _
@echo User selected %1, device Id %_Id%.
@exit /b 0

:SetVar
@set _%1=%2
@exit /b 0

Adb.cmd,用于测试:

Adb.cmd, for testing:

@echo f2ea3410        device
@echo f2fa3410        device

这篇关于提示用户选择设备(从行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆