這是我的字符串得到的TeamViewer(任何版本)服務可執行的位置:如何從wmic輸出中刪除空行?
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.
我怎樣才能得到只有第二行的輸出與可執行文件的正確位置? (或者跳過最新的一行,當然)。
感謝所有提前,並有美好的一天。 Giovanni。
這是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%
和-I添加到請求 - 可以我將整個字符串包含在批處理文件中?我需要指定以前的東西? – Giovanni
如果你想在批處理文件中使用它,你必須將'%A'改爲'%% A'。 –
如果我在'%AA'中更改'%A',批處理不會產生任何東西: for/f「skip = 1 delims =」%% A('wmic path win32_service where'name like'TeamViewer%' 「get pathname^| findstr/r/v」^ $'')do set POSITION = %% A' 'C:\> checkteamviewer.bat C:\>' – Giovanni