【问题标题】:ssh channel Fprintln Line Disorderly go ssh channel writerssh channel Fprintln Line Disorderly go ssh channel writer
【发布时间】:2021-09-08 17:44:58
【问题描述】:

我正在编写一个 ssh 服务器,当我在 ssh.Channel 上运行 fmt.Fprintln 时,它会显示例如:

帮助

  Commands:
             clear      clear the screen
                                          exit       exit the program
                                                                       help       display 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      clear the screen")
}

还有其他方法可以解决这个问题吗? 非常感谢提前

【问题讨论】:

    标签: go ssh channel


    【解决方案1】:

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

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

    看起来您的客户需要 CR+LF,但您只发送 LF 字符。客户端在 Windows 上吗?有没有办法切换到“Unix”行尾?

    【讨论】:

    • 非常感谢,我明白了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多