cpu 使用 for /F 循环查询的批处理文件
batch file for cpu query using for /F loop
需要帮助。
我正在尝试 运行 在批处理文件上执行以下命令以确定机器是 Intel 还是 AMD...
for /F "skip=1 tokens=1" %%i in ('wmic cpu get name') do set chip=%%i
if "%chip%" == "Intel(R)" goto Intel else goto AMD
:Intel echo this is an Intel machine
:AMD echo this is an AMD machine
但我 运行 是个问题。输出结果如下:
for /F "skip=1 tokens=1" %i in ('wmic cpu get name') do set chip=%i
设置芯片=英特尔(R)
设置芯片=
它显示了第二个芯片 "set" 基本上清除了第一个结果。
我需要输入什么才能在第一次响应后停止循环?
设置第一行后,使用 GOTO 退出循环。
@ECHO OFF
FOR /F "skip=1 tokens=1" %%i IN ('wmic cpu get name') DO (
SET "chip=%%i"
GOTO AfterTest
)
:AfterTest
IF "%chip%" == "Intel(R)" (GOTO Intel) ELSE (GOTO AMD)
:Intel
echo this is an Intel machine
ECHO This is Intel.
GOTO AfterAll
:AMD
echo this is an AMD machine
ECHO This is not Intel.
GOTO AfterAll
:AfterAll
获取处理器名称的另一种方法。
@ECHO OFF
FOR /F "delims=" %%p IN ('powershell -NoProfile -Command ^(Get-CimInstance -ClassName CIM_Processor^).Name.Split^(' '^)[0]') DO (
SET "chip=%%p"
)
ECHO %chip%
需要帮助。
我正在尝试 运行 在批处理文件上执行以下命令以确定机器是 Intel 还是 AMD...
for /F "skip=1 tokens=1" %%i in ('wmic cpu get name') do set chip=%%i
if "%chip%" == "Intel(R)" goto Intel else goto AMD
:Intel echo this is an Intel machine
:AMD echo this is an AMD machine
但我 运行 是个问题。输出结果如下:
for /F "skip=1 tokens=1" %i in ('wmic cpu get name') do set chip=%i
设置芯片=英特尔(R)
设置芯片=
它显示了第二个芯片 "set" 基本上清除了第一个结果。
我需要输入什么才能在第一次响应后停止循环?
设置第一行后,使用 GOTO 退出循环。
@ECHO OFF
FOR /F "skip=1 tokens=1" %%i IN ('wmic cpu get name') DO (
SET "chip=%%i"
GOTO AfterTest
)
:AfterTest
IF "%chip%" == "Intel(R)" (GOTO Intel) ELSE (GOTO AMD)
:Intel
echo this is an Intel machine
ECHO This is Intel.
GOTO AfterAll
:AMD
echo this is an AMD machine
ECHO This is not Intel.
GOTO AfterAll
:AfterAll
获取处理器名称的另一种方法。
@ECHO OFF
FOR /F "delims=" %%p IN ('powershell -NoProfile -Command ^(Get-CimInstance -ClassName CIM_Processor^).Name.Split^(' '^)[0]') DO (
SET "chip=%%p"
)
ECHO %chip%