-1

I am looking for way to assign output of a command to a batch variable, but the command internally uses another variable.

When i use the solution specified in Assign Command output to Variable in Batch file

I am getting error that the variable inside the command was not expected at this time.

Please help

Community
  • 1
  • 1
Satheesh
  • 693
  • 1
  • 8
  • 27

1 Answers1

0

I think this will work for you.

Say you command was Echo hi and you wanted to store the output ('hi') into a variable:

Echo hi > out.tmp
set /p var=< out.tmp
del out.tmp

Echo %var%

where var now stores the value of your output. Note: it will only store the first the line of output. If you want to do last line of output comment and I would make it use a for loop instead.

Monacraft
  • 6,187
  • 1
  • 13
  • 27