remote_access.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:opsmgr 作者: open-power-ref-design-toolkit 项目源码 文件源码
def _open_interactive_shell(chan):
    '''    Opens a remote terminal interface
    Note: Works only on unix as it uses POSIX style tty control
    '''

    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, dummy_w, dummy_e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = u(chan.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write(
                            '\r\n*** Terminating the remote shell.\r\n')
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号