[英]Command output set as variable
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我一直在尝试制作一个安装当前 nvidia 驱动程序的脚本,我已经走了很远,但是缺少一件事
I'm trying to use nvidia-smi to find the driver version and here's the command output我正在尝试使用 nvidia-smi 查找驱动程序版本,这是命令 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我一直在尝试在 %driver% 中设置 457.30 这是我目前得到的
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我还尝试了与 findstr 的组合,但结果是一场灾难
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 .在任何情况下, %%g 和 %driver% 返回为empty 。
echo %driver%
returns返回
C:\>echo
ECHO is on.
Any ideas?有任何想法吗?
Thank you for your cooperation.谢谢您的合作。
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.你的变量没有被设置,因为现在你的
nvidia-smi
命令正在抛出一个错误(奇怪的是到标准输出)但是skip=1
正在跳过它,所以没有什么可以设置变量了。
=
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%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.