When paramiko is used to send commands in python, the ctrl+c command is required.
For example, run the top command, then ctrl+c, and then pkill top
def 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
Run nc-nv -l -p 11190 -s 0.0.0.0; ^C when result returns no error
on top; ^C ; mresult returns not found command
Use ^C to simulate ctrl+c
Pass in a string that simulates ctrl+C
0 Answer
这家伙很懒,什么都没留下...