0

I found a batch query to list the stats of my GPU cards, and I wanted to assign the temperature to a variable.

This is the code for the query:

:loop
nvidia-smi --query gpu=index,name,clocks.gr,power.draw,utilization.gpu,fan.speed,temperature.gpu --format=csv,noheader
timeout /t 10 >nul

@cls
goto loop

How can I assign the temperature.gpu to a variable?

Thanks!

Stephen Newell
  • 7,330
  • 1
  • 24
  • 28
  • Possible duplicate of [Assign output of a program to a variable](https://stackoverflow.com/questions/2323292/assign-output-of-a-program-to-a-variable) – phuclv Mar 02 '18 at 06:02
  • Not everyone has a NVidia card and it's utilities. Copy-paste the exact output of your command into your question. – Stephan Mar 02 '18 at 07:46

1 Answers1

0

You can capture the output of a command, use a for /f loop.

The following code is based on assumptions of how the actual output looks like:

for /f "tokens=1-3 delims=," %%A in ('"nvidia-smi --query gpu=index,name,clocks.gr,power.draw,utilization.gpu,fan.speed,temperature.gpu --format=csv,noheader'") do (
  set index=%%A
  set name=%%B
  set clocks=%%C
  set power=%%D
  set utilization=%%E
  set speed=%%F
  set temperature=%%G
)

Once you paste the actual output of your command to your question, I can adapt accordingly.

Stephan
  • 53,940
  • 10
  • 58
  • 91