如何将TCL连接到Python

如何将TCL连接到Python,python,tcl,Python,Tcl,我已经在python上创建了一个脚本,它作为SSH会话(在windows和Linux之间)启动,并允许执行命令。 现在我需要将python脚本与TCL连接起来。 我需要使用TCL调用带有一些参数的脚本,并获得对python控制台的TCL的响应 这是我的Python脚本: 导入线程,paramiko 从paramiko导入客户端 导入时间 类ssh: 客户端=无 外壳=无 def __init__(self, address, username): print("Connecting to

我已经在python上创建了一个脚本,它作为SSH会话(在windows和Linux之间)启动,并允许执行命令。 现在我需要将python脚本与TCL连接起来。 我需要使用TCL调用带有一些参数的脚本,并获得对python控制台的TCL的响应

这是我的Python脚本:

导入线程,paramiko 从paramiko导入客户端 导入时间 类ssh: 客户端=无 外壳=无

def __init__(self, address, username):
    print("Connecting to server.")
    cert = paramiko.RSAKey.from_private_key_file("QA-SIP-Evgenyz.pem")
    self.client = client.SSHClient()
    self.client.set_missing_host_key_policy(client.AutoAddPolicy())
    self.client.connect(address, username=username, pkey=cert)
    self.transport = paramiko.Transport((address, 22))
    self.transport.connect(username=username, pkey=cert)
    thread = threading.Thread(target=self.process)
    thread.daemon = True
    thread.start()
    print("Connected")

def closeConnection(self):
    if self.client is not None:
        self.client.close()
        self.transport.close()

def openShell(self):
    self.shell = self.client.invoke_shell()

def sendShell(self, command):
    if self.shell:
        #print("trying to run command " + command)
        self.shell.send(command + "\r")
        time.sleep(0.6)
        #self.shell.send("\r")

    else:
        print("Shell not opened.")

def process(self):
    global connection
    while True:
        # Print data when available
        if self.shell is not None and self.shell.recv_ready():
            alldata = self.shell.recv(1024)
            while self.shell.recv_ready():
                alldata += self.shell.recv(1024)
            strdata = str(alldata, "utf8")
            strdata.replace('\r', '')
            print(strdata, end = "")
            if strdata.endswith("$ "):
                print("\n$ ", end = "")
  IP = 1.1.1.1

  user = ubuntu

  connection = ssh("IP", "user")

  connection.openShell()

  while True:

    #Just to test the connection

    connection.sendShell("ls -l")
现在我需要找到一种方法,通过TCL和参数调用这个Python类。 我不确定如何编写Python类shpull,以便能够从其他地方获取ards。
还有,“return”是如何工作的,我如何显示控制台?

在您的tcl脚本中,您应该能够使用
exec
调用和您想要传递的参数来执行python代码。您可以在以下tcl中找到更多信息。

您希望将代码作为子进程调用还是在同一进程中调用?