windows – 用于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 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 输出看起来:
有人可以帮助修改批处理文件输出的视图吗?
你的问题是SYSTEMINFO产生ANSII输出(和大多数命令一样),但WMIC产生Unicode输出.两者混合不好.
以下是三种产生ANSII输出的解决方案. 1)将WMIC输出管道传输到MORE 更多将Unicode转换为ANSII.我还将结果传递给FINDSTR以消除空行.该解决方案的唯一问题是具有转换的怪癖导致WMIC输出在每行的末尾具有额外的回车(< CR>< CR>< LF>而不是< 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,defaultipgateway /format:list | more | findstr . ) —————————— 其余的解决方案都经过适当的格式化,没有任何额外的< CR> 2)将WMIC输出写入临时文件,然后输入TYPE 临时文件采用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,defaultipgateway /format:list ) exit /b :wmic wmic %* >test.tmp type test.tmp | findstr . del test.tmp exit /b 3)通过两个FOR / F循环运行WMIC. 第一个FOR / F将WMIC输出转换为ANSII,但它具有额外的< CR>在每一行的末尾.第二个FOR / F剥离不想要的尾随< CR>. FOR / F自动剥离空白行. @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,defaultipgateway /format:list ) exit /b :wmic for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B exit /b (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在Windows上进行Linux的C开发
- xaml – 覆盖主题画笔Windows 10 UWP
- Solidity中uint转string
- 有什么像/ proc for windows
- microsoft-metro – 在Metro应用程序中可以进行Windows身份
- windows-server-2008-r2 – IIS抱怨端口正在被使用
- 在没有cmd.exe弹出窗口的情况下使用popen在Windows上执行任
- Microsoft SQL Server 2008 R2 安装遇到的问题
- 在Windows和Linux上获取Python中唯一的计算机ID
- windows-server-2003 – IIS6:如何解决ASP.NET应用程序中的