我正在尝试比较两个数组,如果有任何数组元素相同,那么我正在打印。我没有得到正确的输出。只显示一个元素(rm.war
)。请参阅以下批处理文件和输出。
代码:
@echo off
setlocal EnableDelayedExpansion
echo "Application list"
set all_apps=(jts.war rm.war ccm.war dm.war relm.war qm.war)
set apps_len=0
for %%b in %all_apps% do (
set /A apps_len=apps_len+1
set apps[!apps_len!]=%%b
echo %%b
)
echo "Installed Applications"
cd /d D:\IBM\WebSphere\AppServer\profiles\AppSrv01\bin
set cmd=call wsadmin.bat -lang jython -f C:/temp/tt.py -user wsadmin -password wsadmin
set insapps_len=0
for /f %%a in ('%cmd%') do (
set /A insapps_len=insapps_len+1
set inslist[!insapps_len!]=%%a
echo %%a
)
echo "Compare arrays"
for /l %%i in (1,+1,%apps_len%) do (
for /l %%j in (%insapps_len%,-1,1) do (
if !apps[%%i]!==!inslist[%%j]! echo !inslist[%%j]!
)
)
输出:
"Application list"
jts.war
rm.war
ccm.war
dm.war
relm.war
qm.war
"Installed Applications"
WASX7209I:
DefaultApplication
admin.war
ccm.war
clmhelp.war
converter.war
ivtApp
jts.war
qm.war
query
rm.war
"Compare arrays"
rm.war
答案 0 :(得分:0)
测试它以查看它是否起作用:
@echo off
set all_apps="jts.war" "rm.war" "ccm.war" "dm.war" "relm.war" "qm.war"
set "installed="
cd /d "D:\IBM\WebSphere\AppServer\profiles\AppSrv01\bin"
set cmd=call wsadmin.bat -lang jython -f C:/temp/tt.py -user wsadmin -password wsadmin
for /f %%a in ('%cmd%') do call set installed="%%a" %%installed%%
echo duplicates:
for %%a in (%all_apps%) do (
for %%b in (%installed%) do (
if "%%~a"=="%%~b" echo %%~a
)
)
pause