I'm trying to capture an SVN log in a string inside a PowerShell script.
On the command line, the encoding of the output is correct, but as soon as I capture it in a string it is not:
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
--------------------------------------------------------------
If it can help, here is the value of $OutputEncoding on my system:
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
Thanks !!
EDIT:
I've also tried the XML output from SVN as follow, but with no luck!
$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;
}
EDIT #2:
I don't know if it may help, but I've noticed that the same issue is there simply using the XML output format directly on the PowerShell console prompt:
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>
Try to put this:
$OutputEncoding = [Console]::OutputEncoding
before your svn call.
It is not directly powershell friendly, but SharpSvn provides the Subversion api directly to .Net, so with that you don't need any parsing at all.
If you are using 'svn log' I would recommend using --xml to avoid having to cope with future output changes.
svn's output is UTF-8 which is transferred to Windows as Unicode, so I would recommend reading as Unicode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With