paramiko中命令行发送如何模拟ctrl+c

问题遇到的现象和发生背景

使用python中paramiko发送命令行时需要发送"ctrl+c"命令
举例:先执行top命令,再执行"ctrl+c",最后执行pkill top

遇到的现象和发生背景,请写出第一个错误信息
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
def __execute_ssh_cmd(self):
    try:
        command = self.case.get("ssh_cmd")
        command = command.removeprefix(" ")
        PyLog().set_log("【执行cmd函数】:" + command)
        if command and command.startswith('scp'):
            ftp = self.ssh_client.client.open_sftp()
            _, server_file, local_file = tuple(command.split(";"))
            ftp.get(server_file, local_file)
            PyLog().set_log("【cmd执行结果】:" + "文件下载成功")
            print("文件下载成功")
        else:
            for command in command.split(';'):
                stdin, stdout, stderr = self.ssh_client.client.exec_command(command, timeout=5, get_pty=True)
                time.sleep(2)
                result = stdout.read(100)
                PyLog().set_log("【cmd执行结果】:" + result.decode('utf-8'))
                print(result)
    except Exception as e:
        # errr=stderr.read(100)
        PyLog().set_log("【cmd执行结果】:" + str(e))
        print(e)
        return
运行结果及详细报错内容

在执行nc -nv -l -p 11190 -s 0.0.0.0 ; ^C时result返回没有报错信息
在执行top ;^C ; pkill top中的^C时mresult中返回not found command

我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%

使用^C模拟ctrl+c

我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”

传入某个字符串用以模拟ctrl+C

搞不懂你到底是出了几个问题,总之发现两个你说的问题,给你说一下
关于 Ctrl +c 你可以使用 paramiko.hotkey('ctrl', 'c') 来执行,另外关于你的那个pkill top,这个是杀死进程的命令,你需要用pkill -9 后面加程序进程的pid,或者直接pkill后面加进程名也可以。

参考:https://www.cnpython.com/qa/88950