我将变量中的字符串与批处理中的实际字符串进行比较时遇到了很多麻烦。这里的脚本:比较批处理中的字符串
set failure=0
for /F "usebackq delims=" %%L in (`"wmic PRINTER where name='10.146.2.52 - HP Color LaserJet CP5225n' GET Name 2>&1"`) do (
::Quotes around variable seem to have no effect. Same result w/ or w/o them.
if /I "%%L"=="No Instance(s) Available." set failure=1
echo %failure% %%L
)
下面是输出:
为什么if语句失败?值显然匹配。请帮忙!!
该病症仍然是错误的。失败未设置为1,但应为bc'%% L'确实等于“无实例可用”。有没有办法处理这个'CR'字符? – ExceptionLimeCat
我看到了问题,它似乎缺少引号,我编辑我的代码 – jeb
我试过了。它没有效果。失败仍然是0. – ExceptionLimeCat