简体   繁体   English

PowerShell 产生不可读的输出

[英]PowerShell Producing Unreadable Output

Image Here For Reference Specifically the text after "Similarity" and "->"图片在这里供参考特别是“相似性”和“->”之后的文字

I have a small PowerShell script that uses ssh to connect to a server and run a command.我有一个小的 PowerShell 脚本,它使用 ssh 连接到服务器并运行命令。 I believe it produces unreadable output due to some of the text having to be in colour.我相信它会产生不可读的输出,因为某些文本必须是彩色的。

I've tried adding the following, but still no luck:我尝试添加以下内容,但仍然没有运气:

$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

To define console encoding you can use following expressions.要定义控制台编码,您可以使用以下表达式。

Choose encoding you need.选择您需要的编码。

$ConsoleEncoding =  [System.Text.Encoding]::UTF8

Apply your encoding to console.将您的编码应用到控制台。

[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding( "$( $ConsoleEncoding.BodyName )" )

Solved it, turns out that the command I needed was ssh -t host command to enable the colour display解决了,原来我需要的命令是ssh -t host command来启用彩色显示

More info here: https://explainshell.com/explain?cmd=ssh+-t+my_host+my_command更多信息在这里: https ://explainshell.com/explain?cmd=ssh+-t+my_host+my_command

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM