问题
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
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.
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 ?
回答1:
PowerShell defaults to UTF16LE, while cmd doesn't do Unicode by default for redirection (which may sometimes end up mangling your data as well).
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
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.
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.
You'd get the same behaviour from cmd if you ran it with cmd /u, by the way.
来源:https://stackoverflow.com/questions/52931215/different-file-size-between-powershell-and-cmd