如果主板制造商为ASUSTek COMPUTER INC.
,如何编写批处理文件以返回true,如果不使用wmic
命令,则如何返回false?
命令如下:
wmic baseboard get Manufacturer
并返回:
Manufacturer ASUSTeK COMPUTER INC.
,我只需要比较字符串ASUSTeK COMPUTER INC.
。
答案 0 :(得分:3)
要捕获set "BOARD="
for /F "skip=1 delims=" %%I in ('
wmic BaseBoard get Manufacturer
') do (
for /F "delims=" %%J in ("%%I") do (
set "BOARD=%%J"
)
)
rem // Compare retrieved string:
if /I "%BOARD%"=="ASUSTeK COMPUTER INC." (
echo True
) else (
echo False
)
命令的输出,请使用for /F
:
for /F
两个嵌套的wmic
循环对于正确转换Unicode wmic
输出是必需的。
但是,您也可以直接过滤wmic BaseBoard where "Manufacturer='ASUSTeK COMPUTER INC.'" get Manufacturer 2>&1 > nul | find /V "" > nul && (echo False) || (echo True)
输出,如下所示:
No Instance(s) Available.
where
子句进行过滤;如果找不到匹配项,则在 STD_ERR 流(句柄2
)上返回2>&1 > nul
。表达式1
将 STD_OUT 流(句柄/V ""
)和redirects STD_ERR 抑制为 STD_OUT ,因此find
将收到它;当流不为空时,搜索表达式find
查找匹配项。如果找到匹配项,0
返回退出代码1
,否则返回&&
; operators ||
和echo
检查退出代码并有条件地执行相应的var board = JXG.JSXGraph.initBoard('jsxgbox', {
axis: true
});
var p1 = board.create('point', [-3,-1], {name: "", label:{visible:false}});
var t1 = board.create('text', [-2.8, -0.8, "Drag me"]);
var g1 = board.create('group', [p1, t1]);
命令。