PowerShell中的SVN输出编码 [英] SVN output encoding in PowerShell

查看:189
本文介绍了PowerShell中的SVN输出编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在PowerShell脚本中的字符串中捕获SVN日志。



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

  PS C:\sandbox> svn log -r1804 https://myserver.here/svn/myrepo 
------------------------------- -------------------------------
r1804 | myname | 2012-06-07 | 1 line
这是我的日志消息与特殊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
这是我的日志消息与一个特殊的caractére
----------------------------- -----------------------------

如果它可以帮助,这里是我的系统上$ 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

谢谢!
$ b

编辑:



我也试过从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;
}

EDIT#2: b
$ b

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

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

日志消息行#1带有特殊的'caractère'
日志消息行#2
---------------- -------------------------------------------------- ------

PS C:\repo> svn log -r999:999 - xml
<?xml version =1.0encoding =UTF-8?>
< log>
< logentry
revision =999>
< author> myname< / author>
< date> 2013-05-29T07:48:20.915930Z< / date>
< msg>日志消息行#1带有特殊的'caractére'
日志消息行#2< / msg>
< / logentry>
< / log>


解决方案

尝试:

  $ OutputEncoding = [Console] :: OutputEncoding 


b $ b

在您的svn呼叫之前。


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.

这篇关于PowerShell中的SVN输出编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆