Editing WMIC output format

后端 未结 2 709
不知归路
不知归路 2020-12-12 00:30
wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Format:Textvaluelist > Output.txt  

Using above command in a batch, I get output as,

相关标签:
2条回答
  • 2020-12-12 01:11

    Wmic can be a weird beast. This works here in Windows 8 32 bit.

    The extra code is needed to remove the trailing Carriage Return.

    @echo off
    setlocal enabledelayedexpansion
    (For /F "tokens=1,* delims==" %%A in ('"wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /value |find "M" "') do (
    set "line=%%A= %%B"
    set "line=!line:~0,-1!"
    echo !line!
    ))>output.txt
    
    0 讨论(0)
  • 2020-12-12 01:14

    First you would consider to convert the WMIC output encoding from Unicode to ANSI to ommit unicode characters (like empty Echoes), a simple trick to do this is filtering the output with FIND/FINDSTR command(s), after applying the output filter you just need to read the output with FOR /F to split the string using the desired tokens value and delims delimitter.

    Here is the code:

    @Echo OFF
    
    (For /F "Tokens=1,* Delims==" %%A in (
        'wmic OS get FreePhysicalMemory^,TotalVisibleMemorySize /Format:list ^| FINDSTR "[0-9]"'
    )DO (
        Echo %%A= %%B
    ))>"File.txt"
    
    Pause&Exit
    
    0 讨论(0)
提交回复
热议问题