Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows wmic命令的批处理脚本中的文本乱码_Windows_Batch File_Wmic - Fatal编程技术网

Windows wmic命令的批处理脚本中的文本乱码

Windows wmic命令的批处理脚本中的文本乱码,windows,batch-file,wmic,Windows,Batch File,Wmic,我正在尝试运行批处理脚本来获取基本的计算机信息,如CPU、RAM和活动网卡 @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

我正在尝试运行批处理脚本来获取基本的计算机信息,如CPU、RAM和活动网卡

@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操作系统名称:
Microsoft Windows 8.1单语言系统型号:
Inspiron 7537系统类型:基于x64的PC全物理 内存:6043 MB CPU信息:

 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
2d:2088:8ba1“}M a C a d d r e s=0c:8b:fd :9 C:80:47

 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 :
c0:0:01

D e f a u l t I p G a t e w a y=I p a D r e s={“1 9 2 .1 6 8.1 9 0.1,“f e 8 0::6 4 b 2:2 a a:e f 6 4:f a 9 a“}M a C a d r e s=0:50:56:c0:0:08


有人可以帮助修改批处理文件输出的视图吗?

您的问题是SYSTEMINFO产生ANSII输出(与大多数命令一样),但WMIC产生Unicode输出。这两者不能很好地混合

以下是三种都能产生ANSII输出的解决方案

1)将WMIC输出传输到更多

MORE将Unicode转换为ANSII。我还将结果传输到FINDSTR以消除空行。此解决方案的唯一问题是,转换的一个怪癖导致WMIC输出在每行末尾有一个额外的回车(
而不是


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

其余的解决方案都已正确格式化,没有任何额外的

2)将WMIC输出写入临时文件,然后键入

temp文件是Unicode格式的,TYPE正确地将Unicode转换为ANSII。我仍然将结果通过管道传输到FINDSTR以消除空行

@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
@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

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

第一个FOR/F将WMIC输出转换为ANSII,但它在每行末尾都有额外的
。第二个FOR/F去掉多余的尾随
。FOR/F自动去掉空行

@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
@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
的Unicode输出(每个字符2字节)转换为单字节编码文本的知识,请参阅和此问题答案中链接的其他主题。