func main() {
client, err := ssh.Dial("tcp", "ip:22", config)
if err != nil {
panic(err)
}
defer client.Close()
session, err := client.NewSession()
if err != nil {
panic(err)
}
defer session.Close()
session.Stdin = os.Stdin
session.Stdout = os.Stdout
session.Stderr = os.Stderr
session.RequestPty("xterm", h, w, ssh.TerminalModes{
ssh.ECHO: 0,
ssh.TTY_OP_ISPEED: 14400,
ssh.TTY_OP_OSPEED: 14400,
ssh.IXANY: 1,
ssh.IMAXBEL: 1,
})
session.Shell()
session.Wait()
}
连接正常。但是打开 htop q 没反应,pageup/down 没反应。ctrl-c 直接主进程退了。
1
chuhades 2022-12-26 21:29:15 +08:00 1
关键词 tty raw mode
|
2
heiher 2022-12-26 21:30:08 +08:00 via Android 1
|
3
chuhades 2022-12-26 21:39:35 +08:00 1
是的。以前写的相关的玩意:
``` if (tcgetattr(1, &t) != 0) { perror("tcgetattr"); goto out; } t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO); t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | PARMRK); t.c_oflag &= ~OPOST; t.c_cc[VMIN] = 1; t.c_cc[VTIME] = 0; if (tcsetattr(1, TCSAFLUSH, &t) != 0) { perror("tcsetattr"); goto out; } ``` |