我正在努力获得所需的输出。
我正在使用2个命令在设备上获取2个variables,跨越多个设备。 我不确定如何交叉引用这些来获得我想要的输出。 我试图看看DEVPACKAGE的内容是否出现在包的内容中,如果它们没有出现在包中会返回一个错误。 我认为它是类似于[ Windows批处理:如何将一个命令的输出设置为一个variables,并在另一个命令中使用它? 但我看不到如何将其应用到我目前的variables。
我明白我的一些方法可能是粗糙的。 我只是认真研究了一个星期的batch file的构build。
DEVPACKAGE
, Package
和尝试输出如下:
::Global @echo off set AAPT=tools\aapt.exe set GREP=tools\grep.exe set CUT=tools\cut.exe :: Check Gold Build applications cls @echo. @echo ------------------------ CHECK APPLICATIONS INSTALLED -------------------------- SETLOCAL ENABLEDELAYEDEXPANSION ::EXTRACT PACKAGENAME FROM APK FOR /F "tokens=1,2 skip=1" %%N IN ('adb devices') DO ( SET IS_DEV=%%O if "!IS_DEV!" == "device" ( SET SERIAL=%%N for /f "delims=" %%P in ('dir /b ^"APKs\*.apk^"') do ( SET APK=%%P for /f "tokens=1 delims=" %%Q in ('%AAPT% d badging APKs\!APK! ^| !GREP! "package: name=" ^| !CUT! -d' -f2') do ( set package=%%Q if "!package!" == "" set package=Unknown ( ) ) ) ) ) ::EXTRACT INSTALLED PACKAGENAME FOR /F "tokens=1,2 skip=1" %%R IN ('adb devices') DO ( if "!IS_DEV!" == "device" ( FOR /F "tokens=1 delims=" %%U IN ('adb shell "pm list packages" ^| !CUT! -f 2 -d ":"^') DO ( SET DEVPACKAGE=%%U ) ) ) ) ) ::CHECK IF INSTALLED APPEARS IN PACKAGENAME FROM APK FOLDER FOR /F "tokens=1,2 skip=1" %%V IN ('adb devices') DO ( if "!IS_DEV!" == "device" ( for /f "delims=" %%W in ('dir /b ^"APKs\*.apk^"') do ( IF !DEVPACKAGE! NEQ !package! ( echo Device !SERIAL! does not have !package! installed ) else ( echo Device !SERIAL! has all APKs installed correctly ) ) ) ) ) ) ENDLOCAL @pause
我会variables输出类似于:
------------------------ CHECK APPLICATIONS INSTALLED -------------------------- Device <SERIAL1> does not have <APK2> installed Device <SERIAL3> does not have <APK1> installed Device <SERIAL22> does not have <APK7> installed Press any key to continue . . .
任何帮助将不胜感激。 提前致谢。
更简单的方法:
setlocal enableDelayedExpansion set "DEVPACKAGE_=!DEVPACKAGE:"=""!" echo !package!|find "!DEVPACKAGE_!" >nul 2>nul && ( echo it is contained )||( echo it is NOT contained )
临时变量DEVPACKAGE_
需要加倍"
所以如果字符串包含它将被FIND
命令正确处理。
你也可以只使用cmd内部命令:
setlocal enableDelayedExpasion if "%package%" equ "!package:%DEVPACKAGE%=!" ( echo it is NOT contained ) else ( echo it is contained )
从理论上讲,第二种方法应该更快,但有更多的字符可能会打破它。