如何在批处理文件中检查adb设备是否已连接? 我在批处理文件中写了“adb devices”,但希望将其作为条件,以便应用程序可以顺畅自动运行。 因此,如果用户没有连接设备,则打印“无设备”并退出应用程序, 否则恢复应用程序。
如何在批处理文件中检查adb设备是否已连接? 我在批处理文件中写了“adb devices”,但希望将其作为条件,以便应用程序可以顺畅自动运行。 因此,如果用户没有连接设备,则打印“无设备”并退出应用程序, 否则恢复应用程序。
对于使用bash或类似shell环境的用户,请尝试使用以下命令:
$ adb get-state 1>/dev/null 2>&1 && echo 'device attached' || echo 'no device attached'
find
并分析错误级别:adb devices -l | find "device product:" >nul
if errorlevel 1 (
echo No connected devices
) else (
echo Found!
..............
)
adb install package.apk
的结果吗?
如果结果 !=Success 就暂停
否则关闭窗口。 - 3llomifind
命令的 errorlevel
,而不是 adb
,所以你在新问题中关于 adb
能够将 errorlevel
设置为除 0
以外的值的说法是错误的。 - Alex P.adb devices -l | find "device product:"
替换为@benjamin-k的回答adb devices | findstr "\<device\>"
,现在可以在已Root和未Root的设备上使用了。 - equiman这是最简单也是最准确的方法,因为它只会找到“device”,而不会找到包含该字符串的其他单词,比如“devices”:
adb devices | findstr "\<device\>"
请注意,findstr只适用于Windows系统,而在Unix终端上不起作用。因此,相应的解决方案是使用find和grep组合。John在这个页面中很好地解释了这一点。