【发布时间】:2019-11-12 16:37:09
【问题描述】:
我正在尝试使用此批处理文件获取当前操作系统。它是:
@echo off
for /f "skip=1 tokens=1* delims= " %%a in ('wmic path win32_operatingsystem get caption') do set _os=%%a %%b %%c %%d
echo You are running %_os%.
goto :eof
我的操作系统是 Windows 7,所以我预计它会返回:
You are running Microsoft Windows 7 Ultimate.
但它返回你正在运行 %c %d。
Why I am getting this result?
【问题讨论】:
-
见Why is the error message “Missing operand” output on processing WMIC output and assigning a value to a variable? 并且只有循环变量
a和b因为tokens=1*。我建议for /f "tokens=2 delims==" %%I in ('%SystemRoot%\System32\wbem\wmic.exe path win32_operatingsystem get caption /Value') do set "_os=%%I" -
您指定了两个令牌(
1和*),但您提供了四个for变量...
标签: for-loop batch-file wmic