PowerShell中的SVN输出编码

Yan*_*eau 9 svn powershell character-encoding

我正在尝试在PowerShell脚本中捕获字符串中的SVN日志.

在命令行中,输出的编码是正确的,但是只要我在字符串中捕获它就不是:

PS C:\sandbox> svn log -r1804 https://myserver.here/svn/myrepo
--------------------------------------------------------------
r1804 | myname | 2012-06-07 | 1 line
Here is my log message with a special caractère
--------------------------------------------------------------
PS C:\sandbox> $tempStr = svn log -r1804 https://myserver.here/svn/myrepo | Out-String
PS C:\sandbox> $tempStr
--------------------------------------------------------------
r1804 | myname | 2012-06-07 | 1 line
Here is my log message with a special caractére
--------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

如果它可以帮助,这是我的系统上$ OutputEncoding的值:

IsSingleByte      : True
BodyName          : us-ascii
EncodingName      : US-ASCII
HeaderName        : us-ascii
WebName           : us-ascii
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 20127
Run Code Online (Sandbox Code Playgroud)

谢谢 !!

编辑:

我也尝试过SVN的XML输出,但没有运气!

$CmdLine = "svn log -r40:HEAD https://myserver.here/svn/myrepo --xml";

$Logs = [xml](Invoke-Expression $CmdLine);

foreach ($Commit in $Logs.log.logentry)
{
   Write-Host $Commit.msg;
}
Run Code Online (Sandbox Code Playgroud)

编辑#2:

我不知道它是否有帮助,但我注意到同样的问题就是直接在PowerShell控制台提示符下使用XML输出格式:

PS C:\repo> svn log -r999:999
------------------------------------------------------------------------
r999 | myname | 2013-05-29 09:48:20 +0200 (mer., 29 mai 2013) | 2 lines

Log message line #1 with a special 'caractère'
Log message line #2
------------------------------------------------------------------------

PS C:\repo> svn log -r999:999 --xml
<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry
   revision="999">
<author>myname</author>
<date>2013-05-29T07:48:20.915930Z</date>
<msg>Log message line #1 with a special 'caractére'
Log message line #2</msg>
</logentry>
</log>
Run Code Online (Sandbox Code Playgroud)

Dav*_*ant 2

尝试这样写:

$OutputEncoding = [Console]::OutputEncoding
Run Code Online (Sandbox Code Playgroud)

在你的 svn 调用之前。