def interactive_ssh_channel(chan, command=None, stdin=sys.stdin):
try:
stdin_is_tty = stdin.isatty()
except Exception:
stdin_is_tty = False
if stdin_is_tty:
oldtty = termios.tcgetattr(stdin)
chan.get_pty()
if command is not None:
chan.exec_command(command)
try:
if stdin_is_tty:
tty.setraw(stdin.fileno())
tty.setcbreak(stdin.fileno())
return utils.CommandStatus(*drain_ssh_channel(chan, stdin))
finally:
if stdin_is_tty:
termios.tcsetattr(stdin, termios.TCSADRAIN, oldtty)
评论列表
文章目录