我正在努力获得所需的输出。Windows批处理 - 检查一个命令变量是否出现在另一个命令变量中
我正在使用2个命令在设备上获取2个变量,跨多个设备。我不确定如何交叉引用这些来获得我想要的输出。我试图看看DEVPACKAGE中的任何内容是否出现在包的内容中,如果它们没有出现在包中会返回错误。我认为这与[Windows Batch: How to set the output of one command as a variable and use it in another command?类似,但我看不出如何将其应用于当前变量。
我明白我的一些方法可能是粗略的。我只是认真研究了一周的批处理文件构建。
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
我会类似于可变输出:
------------------------ 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 . . .
任何帮助,将不胜感激。提前致谢。
你的代码中没有VAR1和VAR2 .... – npocmaka
我想你想检查'DEVPACKAGE'是否包含'package'?或者其他方式? – npocmaka
thats correct我想检查'DEVPACKAGE'是否出现在'package' – beecho01