1

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.

2
  • Are you saying you receive no error message when you run that code? Commented Dec 22, 2021 at 20:24
  • nope, the variable is just empty, echo %driver% returns nothing Commented Dec 22, 2021 at 20:25

1 Answer 1

2

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%
Sign up to request clarification or add additional context in comments.

4 Comments

SomethingDark, I just want to make sure I am not going crazy and that the original code the user was using should have caused an ERROR and should have been visible if the user was running the batch file from the command line.
@Squashman - I was surprised myself, but nvidia-smi's error went to stdout for some reason and got skipped. If the skip=1 hadn't been there, they definitely would have seen it.
I guess I will run that code later when I am on my desktop. Sometimes you just have to see it to believe it.
Yeah, confirmed it myself now as well, @Squashman. Invalid combination of input arguments. Please run 'nvidia-smi -h' for help. when I remove skip=1 but no result with skip. Event when redirecting sterr to nul. FOR /F "tokens=*" %g IN ('nvidia-smi --query-gpu=driver_version --format=csv 2^>nul') do echo %g Some programs do infact write their errors to the stdout stream, I experienced this quite a bit recently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.