Python cmd over socket,但readline / completion不起作用

时间:2018-04-07 06:37:56

标签: python sockets unix autocomplete readline

我正在尝试使用带有cmd模块的python和通过套接字进行通信来构建类似shell的接口。目前我使用telnet作为客户端与...进行交互。

一切都按预期工作,但是readline / completion功能(光标键图或Tab出现在屏幕上) 当相同的代码没有通过套接字,并使用默认的stdin / stdout工作正常。

以下是代码部分:

from cmd import Cmd
import socket

# Cmd shell
class my_shell (Cmd):
    """Simple shell"""
    def __init__(self, SockFile):
        Cmd.__init__(self, stdin=SockFile, stdout=SockFile)
        sys.stdout = SockFile
        self.use_rawinput = False

    def do_bye(self, line):
        return True
    def do_EOF(self, line):
        return True

def my_worker(Conn):
    try:
        sockFile = Conn.makefile()
        shell = my_shell ( sockFile ) 
        shell.cmdloop() 
    except:
        pass
    finally:
        Conn.close()

有什么想法吗?

0 个答案:

没有答案
相关问题