Skipping last empty line of WMIC command output in batch

前端 未结 2 633
-上瘾入骨i
-上瘾入骨i 2021-01-29 04:57

I am trying to format the output of a command in JSON as such:

echo \"patches\" : {
set patches=\"wmic qfe get HotfixID\"
for /f \"skip=1\" %%i in (\' %patches%         


        
2条回答
  •  误落风尘
    2021-01-29 05:32

    Skipping last empty line of WMIC command output in batch

    The simplest solution is to use findstr to remove the blank lines:

    for /f "skip=1" %%i in ('%patches% ^| findstr /r /v "^$"')
    

    No extra for loop required.


    Further Reading

    • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
    • findstr - Search for strings in files.

提交回复
热议问题