I am struggling to get the output required.
I am using a 2 commands to get 2 variables on a device, across multiple devices. I am unsure how to cross reference these to get the output I would like. I am trying to see if any of the contents of DEVPACKAGE appears in the contents of packages, if they don't appear in packages return an error. I assume it is something similar to [Windows Batch: How to set the output of one command as a variable and use it in another command? but I cannot see how to apply it to my current variables.
I understand that some of my methods may be crude. I have only been seriously looking into batch file construction for a week.
DEVPACKAGE
, Package
and attempted output are as below:
::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
I would a variable output similar to:
------------------------ 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 . . .
Any help would be greatly appreciated. Thanks in advance.