1

Currently trying to loop trough an array of strings while searching for specific string in a file. Not getting the output that I would like.

@echo off

wmic qfe get HotfixID > WinUpdateList.txt && set file=WinUpdateList.txt

set patch[0]=KB4012212
set patch[1]=KB4014985
set patch[2]=KB4014573
set patch[3]=KB4015546
set patch[4]=KB4018271
set patch[5]=KB4019263
set patch[6]=KB4019264

for /L %%a in (0,1,6) do (
    >nul find /C "%patch[%%a]%" %file% && (
      echo %patch[%%a]% was found.
    ) || (
      echo %patch[%%a]% was NOT found.
    )
)
titant3ch
  • 81
  • 8
  • It would be quite helpful if you told us what output you want... For sure the lack of [delayed expansion](http://ss64.com/nt/delayedexpansion.html) is one problem; perhaps the Unicode output of `wmic` is another one... – aschipfl May 29 '17 at 17:13
  • I suggest you to read [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini May 29 '17 at 19:06

1 Answers1

1

Was able to get the result I needed with the change below.

   for /L %%a in (0,1,6) do (
        >nul find /C "!patch[%%a]!" %file% && (
            echo !patch[%%a]! was found.
        ) || (
            echo !patch[%%a]! was NOT found.
        )
    )
titant3ch
  • 81
  • 8