我正在使用powershell创建文件,我需要此文件为UTF8编码,至此所有尝试尝试都失败了。将Powershell创建的文件的编码更改为UTF8而不是UCS-2 LE
检查记事本++中的文件显示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)
在控制台的输出被示数仍然按照上面。
嗨安德烈,我已经尝试了这两个建议,后者是我最初的尝试,前者是我刚才尝试过的。我仍然收到控制台中的错误,但它仍然以不希望的编码创建它。你介意看看编辑过的帖子,看看是否有明显的错误吗? – null
当然,段'$ text =“asdaasdad” $ filename =“c:\ GAAAAAH.conf” [IO.File] :: WriteAllLines($ filename,$ text,[System.Text.Encoding]: :UTF8)\t'本身工作正常。 – null
它是在一个函数内,如果有帮助,它在文件内部调用。 – null