0

I'm trying to get the output of the WMIC command to assign variables to each line.

I'm trying to get the out put to look like this:

1 first program installed

2 second program installed

3 third program installed

4 fourth program installed

5 ...etc

@Echo off

wmic /output:file.txt product get name /format:csv

rem wmic product get name

@Echo Off
SetLocal EnableDelayedExpansion
Set n=

Set _InputFile=c:\users\jorge\desktop\file.txt
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
Set _var!n!=%%I
)
:: This line will display the variables just assigned
:: For testing only, delete when not needed
Set _
EndLocal

pause
George Gill
  • 43
  • 1
  • 6

1 Answers1

0

This won't work because wmic will give you Unicode file that for /f can not read (see here). Workaround is to use ('type file') instead:

@Echo off

:: not really need a csv here...
wmic /output:file.txt product get name /format:table

Set n=0
:: Suggest to use internal call :label rather than delayed expansion
For /F "tokens=* skip=1 delims=" %%I IN ('type file.txt') DO @call :Assign %%I
Set _
pause
goto :EOF

    :Assign
    Set /a n+=1
    Set _var%n% = %*
    goto :EOF
BartekB
  • 8,492
  • 32
  • 33