0

我正在运行一个 for 循环来遍历要停止的服务列表,但我遇到了引号问题,而且结果也很不寻常。

for /f "tokens=* delims= " %%a in ('wmic service where ^(displayname like "%%tsm%%"^) get name ^| findstr "TSM"') do echo "%%a"

我的结果是这样的:

"Service Name
"Service Name

如果我切换到:

for /f "tokens=* delims= " %%a in ('wmic service where ^(displayname like "%%tsm%%"^) get name ^| findstr "TSM"') do echo ""%%a""

结果是:

""Service Name
""Service Name

而且,如果我切换到:

for /f "tokens=* delims= " %%a in ('wmic service where ^(displayname like "%%tsm%%"^) get name ^| findstr "TSM"') do echo ^"%%a^"

结果:

"Service Name
"Service Name

显然发生了一些我不明白的事情,因为我根本无法让它将我的结果封装在引号中,因此我可以运行诸如 net stop 或 sc delete 之类的命令。

4

1 回答 1

0

试试这个:

for /f "tokens=* delims= " %%a in ('wmic service where ^(displayname like "%%tsm%%"^) get name ^| findstr "TSM"') do (
for /f "delims=" %%i in ("%%a") do echo "%%i"
)

这是由于 wmic ( CRLFCR) 的“行尾”符号。

于 2013-05-24T00:21:14.603 回答