0

I have a .exe that prints the results of multiple devices connected to the PC. Each item is on a separate line, however, depending on what's connected the results can 1 to many devices.

how do i set each one to a separate variable?

testapp.exe -l
340e42e15fc02fb99e7caf66565d3c881081390c
4e8e93bd2a401c34e3d0d257de07af5d624521c6

the below will only work when the result is one device

for /f "tokens=1 " %%a in ('testapp.exe') do set DEVICE1=%%a

ideas?

rcmpayne
  • 163
  • 2
  • 15

2 Answers2

0

You may use an array to store each result in each array element:

@echo off
setlocal EnableDelayedExpansion

set n=0
for /F %%a in ('testapp.exe -l') do (
   set /A n+=1
   set "device[!n!]=%%a"
)

echo The devices are:
for /L %%i in (1,1,%n%) do echo %%i- !device[%%i]!
Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Thanks, what %varible% do i use with the results? echo %device% | echo %device1% | ETC – rcmpayne May 19 '16 at 18:47
  • If `device` is the name of the array, then `%device[1]%` is the first element, `%device[2]%` is the second one, etc. See [here](https://en.wikipedia.org/wiki/Array_data_structure#One-dimensional_arrays), or [here](https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Indexing), or the description at the array link given above... – Aacini May 19 '16 at 19:20
0
@echo off
setlocal enabledelayedexapansion
set i=0
for /f %%a in ('testapp.exe -l') do (
  set /a i+=1
  set device!i!=%%a
)
echo %i% devices:
set device
Stephan
  • 53,940
  • 10
  • 58
  • 91