ssh通道Fprintln行无序地进行ssh通道写入

huangapple go评论85阅读模式
英文:

ssh channel Fprintln Line Disorderly go ssh channel writer

问题

我正在写一个SSH服务器,当我在ssh.Channel上运行fmt.Fprintln时,它显示如下:
>>help

  Commands:
             clear      清除屏幕
                                          exit       退出程序
                                                                       help       显示帮助

打印行的样式不符合预期。

我的代码:

func handleShells(channel ssh.Channel, sshConn *ssh.ServerConn, reg map[string]interface{}) {
    defer channel.Close()
    fmt.Fprintln(channel, ">>help")
    fmt.Fprintln(channel, "Commands:")
    fmt.Fprintln(channel, "  clear      清除屏幕")
}

有没有其他方法来解决这个问题?
非常感谢。

英文:

I am writing a ssh server,when i run fmt.Fprintln on ssh.Channel,it show e.g:
>>help

  Commands:
             clear      clear the screen
                                          exit       exit the program
                                                                       help       display help

the print line style is not expected

my code:

func handleShells(channel ssh.Channel, sshConn *ssh.ServerConn, reg map[string]interface{}) {
    defer channel.Close()
    fmt.Fprintln(channel, ">>help")
    fmt.Fprintln(channel, "Commands:")
    fmt.Fprintln(channel, "  clear      clear the screen")
}

is there any other way to solve this problem?
Thanks alot in advance

答案1

得分: 1

如果输出显示为“stairs”这样,通常表示行尾不匹配。有三种行尾样式:

  • CR+LF(Windows)
  • 仅 LF(Unix)
  • 仅 CR(旧版 macOS)

看起来你的客户端期望的是 CR+LF,但你只发送了 LF 字符。客户端是在 Windows 上吗?它有切换到“Unix”行尾的方法吗?

英文:

If the output appears as "stairs" like this, that's typically a sign of a mismatch in line endings. There are three line-ending styles:

  • CR+LF (Windows)
  • LF only (Unix)
  • CR only (old macOS)

It looks like your client expects CR+LF, yet you are sending only LF characters. Is the client on Windows? Does it have a way to switch to "Unix" line endings?

huangapple
  • 本文由 发表于 2021年6月25日 17:58:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/68129155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定