title: How can I remove empty lines from wmic output?
body: <p>This is my string to obtain the position of TeamViewer (any version) service executable:</p>
  
  <pre><code>for /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer%'" get pathname') do set POSITION=%A
  </code></pre>
  
  <p>The problem is caused by <code>wmic</code> because it includes an empty line at the end of result (on Windows 7 command) and this is the output:</p>
  
  <pre><code>C:\Users\giovanni&gt;for /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer%
  '" get pathname') do set POSITION=%A
  
   :\Users\giovanni&gt;set POSITION="C:\Program Files\TeamViewer\Version8\TeamViewer_Service.exe"
  
   :\Users\giovanni&gt;set POSITION=
  
  C:\Users\giovanni&gt;echo %position%
  ECHO enabled.
  </code></pre>
  
  <p>How I can get only the second line of the output with the correct position of the executable? (or skip the latest line, of course).</p>
  
  <p>Thanks all in advance and have a nice day.
  Giovanni.</p>
  
  <p>This is checktv.bat:</p>
  
  <pre><code>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%
  </code></pre>