I've been trying to make a script that installs the current nvidia driver, I've gone pretty far but there's one thing missing
I'm trying to use nvidia-smi to find the driver version and here's the command output
C:\>nvidia-smi --query-gpu=driver_version --format=csv
driver_version
457.30
I've been trying to set 457.30 in %driver% here's what I got so far
FOR /F "tokens=* skip=1" %%g IN ('nvidia-smi --query-gpu=driver_version --format=csv') do (SET "driver=%%g")
I also tried a combination with findstr but that ended up being a disaster
for /F "tokens=* skip=1" %%g in ('nvidia-smi --query-gpu=driver_version --format=csv ^| findstr "."') do set driver=%%g
In any case, %%g and %driver% return as empty.
echo %driver%
returns
C:\>echo
ECHO is on.
Any ideas?
Thank you for your cooperation.
CodePudding user response:
Your variable isn't getting set because right now your nvidia-smi
command is throwing an error (to stdout, curiously) but skip=1
is skipping over it so there's nothing left to set the variable to.
=
is one of the default delimiters for strings and so both of the =
symbols in your command need to be escaped for your query to be executed correctly.
@echo off
for /F "delims=" %%g IN ('nvidia-smi --query-gpu^=driver_version --format^=csv ^| find "."') do set "driver=%%g"
echo %driver%