windows – 如何从wmic输出中删除空行?

这是获取TeamViewer(任何版本)服务可执行文件位置的字符串:
for /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer%'" get pathname') do set POSITION=%A

问题是由wmic引起的,因为它在结果的末尾包含一个空行(在Windows 7命令中),这是输出

C:\Users\giovanni>for /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer%
'" get pathname') do set POSITION=%A

 :\Users\giovanni>set POSITION="C:\Program Files\TeamViewer\Version8\TeamViewer_Service.exe"

 :\Users\giovanni>set POSITION=

C:\Users\giovanni>echo %position%
ECHO enabled.

如何只使用可执行文件的正确位置获得输出的第二行? (当然也可以跳过最新的一行).

提前谢谢所有人,祝你有个愉快的一天.
乔瓦尼.

这是checktv.bat:

for /f "skip=1 delims=" %%A in ('wmic path win32_service where "name like 'TeamViewer%'" get pathname ^| findstr /r /v "^$"') do set POSITION=%%A
echo %POSITION%
像这样:
for /f "skip=1 delims=" %A in (
  'wmic path win32_service where "name like 'TeamViewer%'" get pathname ^| findstr /r /v "^$"'
) do set POSITION=%A

findstr / r / v“^ $”从输出删除空行.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...