Powershell 编码默认输出 [英] Powershell Encoding Default Output

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

问题描述

我在 TFS 构建中运行的 powershell 脚本存在以下问题.这两个问题都与 TFS 无关,可以使用简单的 powershell 命令行窗口重现.

I have the following problems with a powershell script that runs inside a TFS build. Both problems are unrelated to TFS and can be reproduced using an simple powershell command line window.

1) 与 TFS 完全无关.在管道方面,Powershell 似乎不喜欢德语变音.

1) Completely unrelated to TFS. It seems Powershell does not like german umlauts when it comes to pipe.

1a) 这行代码运行良好,所有变音都正确显示

1a) This line of code works fine and all umlauts are shown correctly

.\TF.exe hist "$/Test" /recursive /collection:https://TestTFS/tfs/TestCollection /noprompt /version:C1~T

1b) 这条线与变音符号混淆

1b) This line messes with umlauts

.\TF.exe hist "$/Test" /recursive /collection:https://TestTFS/tfs/TestCollection /noprompt /version:C1~T | Out-String

最初我尝试了 Out-File 并仅将编码更改为每个排版(UTF8、unicode、UTF32...)中的变音符号编码错误

Initially I tried Out-File and changed encoding only to the that the umlauts are encoded wrong in every typeset (UTF8, unicode, UTF32,...)

我真的不知道如何从标准输出中提取字符串并获得正确的变音符号.

I really do not know how to extract a string from standard output and get the umlauts right.

2) 当使用 Out-File 或 Out-String 时,输出中的每一行在 80 个字符后都被截断,这似乎是默认的屏幕缓冲区设置.我如何在 powershell 脚本中更改它,为什么它在重定向输出时甚至会产生影响.

2) When using Out-File or Out-String each line in the output got truncated after 80 characters with seems to be the default screen buffer setting. How can I change that inside a powershell script and why does it even have an impact when redirecting the output.

推荐答案

问题 2 不是 Powershell 问题.tfs 文档 说明了以下关于默认 /format 参数(即 /format:brief)

Problem number 2 is not a Powershell problem. tfs documentation says following about default /format parameter (i.e. /format:brief)

部分数据可能会被截断.

Some of the data may be truncated.

/format:detailed 没有那个警告,但它返回更多信息,你可以在执行 Out-StringOut- 之前用 Powershell 处理这些信息文件.

/format:detailed does not have that warning, but it returns more information, which you can process with Powershell before doing Out-String or Out-File.

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

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