【发布时间】:2016-09-29 10:03:28
【问题描述】:
我正在使用powershell创建一个文件,我需要这个文件是UTF8编码的,到目前为止我尝试过的所有尝试都失败了。
在 Notepad++ 中检查文件显示 UCS-2 LE BOM 作为编码。 powershell可以改用UTF8吗?
到目前为止,我已经尝试过 -encoding utf8,目前我正在使用[IO.File]::WriteAllLines($filename, $text)
可能存在导致问题的潜在问题(原谅我,对 Powershell 来说非常新),因为我在控制台中收到此错误,但是正在创建文件:
Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
+ CategoryInfo : InvalidArgument: (:) [Out-File], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.OutFileCommand
+ PSComputerName : 50.19.209.240
ChangeFileModeByMask error (3): The system cannot find the path specified.
+ CategoryInfo : NotSpecified: (ChangeFileModeB...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : 50.19.209.240
编辑:
在给出答案后进行编辑以提供更多信息。
文件中的详细信息:
write-host "Creating Application.conf in UTF-8"
$filename = "c:\application.conf"
[IO.File]::WriteAllLines($filename, $text, [System.Text.Encoding]::UTF8)
控制台中的输出仍然按照上述错误。
【问题讨论】:
标签: powershell encoding utf-8