Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Batch file 请参阅下面的批处理文件。为什么我的批处理文件在输出到文本文件时显示日文/中文字符?_Batch File_Cmd_Command - Fatal编程技术网

Batch file 请参阅下面的批处理文件。为什么我的批处理文件在输出到文本文件时显示日文/中文字符?

Batch file 请参阅下面的批处理文件。为什么我的批处理文件在输出到文本文件时显示日文/中文字符?,batch-file,cmd,command,Batch File,Cmd,Command,请参阅下面的批处理文件。为什么我的批处理文件在输出到文本文件时显示日文/中文字符?我正在自动化我的安装过程,因为我一周安装了很多台电脑。在命令提示符下执行以下命令时,它返回正确的输出,但在批处理文件中它显示了一堆汉字 systeminfo | findstr /B /C:"OS Name" systeminfo | findstr c:/"installed Physical MEmory" 这是完整的批处理文件和输出 set OLDNAME=%computername% set /p var

请参阅下面的批处理文件。为什么我的批处理文件在输出到文本文件时显示日文/中文字符?我正在自动化我的安装过程,因为我一周安装了很多台电脑。在命令提示符下执行以下命令时,它返回正确的输出,但在批处理文件中它显示了一堆汉字

systeminfo | findstr /B /C:"OS Name"
systeminfo | findstr c:/"installed Physical MEmory"
这是完整的批处理文件和输出

set OLDNAME=%computername%
set /p var1="Enter the PC Name that will be used when joined to the domain: "

wmic computersystem where caption="%OLDNAME%" rename %var1% 

>output.txt (
wmic csproduct get name
wmic bios get serialnumber
systeminfo | findstr /B /C:"OS Name"
wmic cpu get name
systeminfo | findstr c:/"installed Physical MEmory"

)
输出如下:

MYPC                        
Surface with Windows 8 Pro  
SerialNumber  (Witheld for obvious reasons)
协丠浡㩥†††††††††䴠捩潲潳瑦圠湩潤獷ㄠ‰牐൯ഊ上愀洀攀                                      ഀ਀䤀渀琀攀氀⠀刀⤀ 䌀漀爀攀⠀吀䴀⤀ 椀㔀ⴀ㌀㌀㄀㜀唀 䌀倀唀 䀀 ㄀⸀㜀 䜀䠀稀  ഀ਀吀瑯污倠票楳慣敍潭祲›††ⰳ㠹‰䉍਍癁楡慬汢⁥桐獹捩污䴠浥牯㩹㈠㈬ㄳ䴠ൂ

想法?

命令的输出是什么
CHCP
?当写入文件时,wmic.exe使用UTF-16。这实际上是这个愚蠢的程序唯一正常的输出。当写入控制台或管道时,即使控制台未使用OEM代码页,it也会使用有损编码对OEM代码页进行硬编码。如果从上面看不明显,您会看到非Unicode
systeminfo
输出中的CJK字符与wmic输出混合在一起。wmic使用UTF-16 BOM启动output.txt文件,因此大多数程序都会正确地尝试将
systeminfo
输出作为UTF-16编码文本处理,显示为CJK字符。谢谢。我无论如何都不是程序员,所以我没有完全理解这个问题。有什么解决问题的建议吗?我很感激!不能将输出UTF-16的命令的输出与输出使用旧代码页编码的文本的命令相结合。但请注意,我说过wmic.exe在写入管道时将输出用OEM代码页编码的文本。这意味着您可以使用
for/f
循环,如果您不关心有损编码,这在您的情况下应该不是问题。