英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论