在WMIC命令批处理脚本文本断章取义 [英] Text garble in batch script for wmic command

查看:126
本文介绍了在WMIC命令批处理脚本文本断章取义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行该批处理脚本,如CPU,内存和活动网络card.Here获得基本的计算机信息是我的code

I'm trying to run the batch script to acquired the basic computer information like CPU,RAM and active Network card.Here is my code

@Echo OFF

set newline=^& echo.

echo Manufacturer Information> test1.txt

systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" >>test1.txt

echo CPU Information:>> test1.txt

wmic cpu get Name /Format:list >> test1.txt

echo %newline%Process Information:>> test1.txt

wmic computersystem get NumberofProcessors /Format:list >> test1.txt

echo %newline%NIC Information:>> test1.txt

wmic nicconfig where "IPEnabled=TRUE" get ipaddress, macaddress,defaultipgateway /format:list >>test1.txt

输出如下:

制造商信息主机名:DK-IT操作系统名称:结果
  微软的Windows 8.1单语言系统型号:结果
  的Inspiron 7537系统类型:基于x64的PC总物理
  内存:6,043 MB CPU信息:

Manufacturer Information Host Name: DK-IT OS Name:
Microsoft Windows 8.1 Single Language System Model:
Inspiron 7537 System Type: x64-based PC Total Physical Memory: 6,043 MB CPU Information:

 N a m e = I n t e l ( R )   C o r e ( T M )   i 5 - 4 2 0 0 U   C P U   @   1 . 6 0 G H z 



Process Information:


 N u m b e r O f P r o c e s s o r s = 1 



NIC Information:


 D e f a u l t I P G a t e w a y = { " 1 0 . 5 . 1 . 1 " }     I P A d d r e s s = { " 1 0 . 5 . 4 . 5 4 " , " f e 8 0 : : 1 0 e b : 1 d


  
  

2 D:2 0 8 8:8 B A 1} M A C A D D - [R(E S)S = 0 C:8 A:F D
  :9 C:8 0:4 7

2 d : 2 0 8 8 : 8 b a 1 " } M A C A d d r e s s = 0 C : 8 B : F D : 9 C : 8 0 : 4 7

 D e f a u l t I P G a t e w a y =     I P A d d r e s s = { " 1 9 2 . 1 6 8 . 1 9 9 . 1 " }     M A C A d d r e s s = 0 0 : 5 0 : 5 6 :


  
  

C 0:0 0:0 1

C 0 : 0 0 : 0 1

D E F为U L T I P G A T E w的Y =我P A D D - [R(E S)S = {1 9 2
  。 1 6 8。 1 9 0。 1,F E 8 0:6 4 B 2:2 A A A:电子网6 4:F
  一个9} M A C A D D - [R(E S)S = 0 0:5 0:5 6:C 0:0 0:0 8

D e f a u l t I P G a t e w a y = I P A d d r e s s = { " 1 9 2 . 1 6 8 . 1 9 0 . 1 " , " f e 8 0 : : 6 4 b 2 : 2 a a a : e f 6 4 : f a 9 a " } M A C A d d r e s s = 0 0 : 5 0 : 5 6 : C 0 : 0 0 : 0 8

有人能帮助修改批处理文件输出的看法?

Can someone help to modify the view of batch file output?

推荐答案

您的问题是SYSTEMINFO产生ANSII输出(如大多数命令),但WMIC产生的Uni code输出。这两个不拌匀。

Your problem is SYSTEMINFO produces ANSII output (as do most commands), but WMIC produces Unicode output. The two do not mix well.

下面是三种解决方案,所有产生ANSII输出。

Below are three solutions that all produce ANSII output.

1)管的输出WMIC更多

更多转换的Uni code至ANSII。我也管导致提供给Findstr消除空白行。这种解决方案的唯一的问题是,与转换的一个怪癖导致WMIC输出必须在每行的末尾一个额外的回车(< CR>< CR>< LF> 而不是< CR>< LF>

MORE converts Unicode to ANSII. I also pipe that result to FINDSTR to eliminate blank lines. The only problem with this solution is that a quirk with the conversions causes the WMIC output to have an extra carriage return at the end of each line (<CR><CR><LF> instead of <CR><LF>)

@echo OFF
>test1.txt (
  echo Manufacturer Information:
  systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:"

  echo(
  echo CPU Information:
  wmic cpu get Name /Format:list | more | findstr .
  wmic computersystem get NumberofProcessors /Format:list | more | findstr .

  echo(
  echo NIC Information:
  wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list | more | findstr .
)


------------------------------


------------------------------

其他的解决方案都是正确的格式,没有任何多余的&LT; CR&GT;

The remaining solutions are all properly formatted, without any extra <CR>

2)收件WMIC输出到一个临时文件,然后键入

该临时文件是在统一code画幅,然后键入正确转换的Uni code至ANSII。我还管结果FINDSTR消除空白行。

The temp file is in Unicode format, and TYPE properly converts the Unicode to ANSII. I still pipe the result to FINDSTR to eliminate blank lines.

@echo OFF
>test2.txt (
  echo Manufacturer Information:
  systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:"

  echo(
  echo CPU Information:
  call :wmic cpu get Name /Format:list
  call :wmic computersystem get NumberofProcessors /Format:list

  echo(
  echo NIC Information:
  call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list
)
exit /b

:wmic
wmic %* >test.tmp
type test.tmp | findstr .
del test.tmp
exit /b


3)运行WMIC通过两个FOR / F循环。

第一FOR / F转换WMIC输出ANSII,但它有额外的&LT; CR&GT; 在每行的末尾。 FOR / F第二剥去不需要的结尾&LT; CR&GT; 。 FOR / F自动去除空行。

The first FOR /F converts the WMIC output to ANSII, but it has the extra <CR> at the end of each line. The second FOR /F strips off the unwanted trailing <CR>. FOR /F automatically strips blank lines.

@echo OFF
>test3.txt (
  echo Manufacturer Information:
  systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:"

  echo(
  echo CPU Information:
  call :wmic cpu get Name /Format:list
  call :wmic computersystem get NumberofProcessors /Format:list

  echo(
  echo NIC Information:
  call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list
)
exit /b

:wmic
for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B
exit /b

这篇关于在WMIC命令批处理脚本文本断章取义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆