问题描述
wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Format:Textvaluelist > Output.txt
在批量使用上面的命令
,我得到作为输出,
Using above command in a batch, I get output as,
FreePhysicalMemory=1140860
TotalVisibleMemorySize=2095492
我想等号(=)符号后添加一个空格,sothat它可能看起来像;
I want to add a single space after equal (=) sign ,sothat it may look like;
FreePhysicalMemory= 1140860
TotalVisibleMemorySize= 2095492
我下面想,但得到的错误:命令的语法不正确
For /F "tokens=1 delims==" %%A in ('wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Format:Textvaluelist') do
echo %%A %%B > Output.txt
或有任何其他方式来获得使用批处理中要求的格式输出?
or is there any other way to get the output in required format using batch ?
推荐答案
首先,你会考虑到 WMIC
输出编码从转换成统一code
到 ANSI
来ommit UNI code字符(如空回声),一个简单的技巧来做到这一点与 FIND / FINDSTR 命令(S),采用输出滤波后,你只需要阅读 FOR / F
来输出使用所需的标记分割字符串
值和 delims
delimitter。
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.
下面是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
这篇关于编辑WMIC输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!