Powershell和cmd之间的文件大小不同 [英] Different file size between powershell and cmd
问题描述
我正在使用一个小的 processconf.js
工具从多个 .json 文件构建一个 configuration.json
文件.
I am using a little processconf.js
tool to build a configuration.json
file from multiple .json files.
这是我正在使用的命令:
Here the command I am using :
node processconf.js file1.json file2.json > configuration.json
我暂时使用了 cmd
,但是今天我尝试使用 Powershell
,并以某种方式从相同文件和相同命令,我确实有不同的结果.
I was using cmd
for a moment, but today I tried using Powershell
and somehow from the same files and the same command I do have different results.
一个文件为 33kb (cmd),另一个文件为 66kb (powershell),查看它们具有完全相同的行,我看不到任何视觉差异, 这是为什么 ?
One file is 33kb(cmd) the other 66kb(powershell), looking at the files they have the exact same lines and I can't find any visual differences, why is that ?
推荐答案
PowerShell默认为UTF16LE,而 cmd
默认情况下不对重定向进行Unicode处理(可能有时最终也会破坏您的数据).
PowerShell defaults to UTF16LE, while cmd
doesn't do Unicode by default for redirection (which may sometimes end up mangling your data as well).
如果您未在PowerShell中使用重定向运算符,而是使用 Out-File
,则可以指定一种编码,例如
If you don't use the redirection operator in PowerShell but instead Out-File
you can specify an encoding, e.g.
node processconf.js file1.json file2.json | Out-File -Encoding Utf8 configuration.json
我认为-编码Oem
与 cmd
行为有些相同,但通常不支持Unicode,并且涉及转换.
I think -Encoding Oem
would be somewhat the same as the cmd
behaviour, but usually doesn't support Unicode and there's a conversion involved.
当然,重定向运算符没有提供用于指定任何选项的规定,因此,当您关心确切的输出格式时,它通常不是最佳选择.而且由于PowerShell与Unix Shell相反,处理对象,文本和随机二进制数据是完全不同的事情.
The redirection operator of course has no provisions for specifying any options, so it's often not the best choice when you care about the exact output format. And since PowerShell, contrary to Unix shells, handles objects, text and random binary data are very different things.
顺便说一句,如果您使用 cmd/u
运行 cmd
中获得相同的行为.
You'd get the same behaviour from cmd
if you ran it with cmd /u
, by the way.
这篇关于Powershell和cmd之间的文件大小不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!