Python Paramiko 将 CTRL+C 发送到 ssh shell [英] Python Paramiko send CTRL+C to an ssh shell
问题描述
我正在使用 Paramiko 调用 shell,以便通过 ssh 连接使用 CLI.这个 CLI 的问题是如果我不使用 CTRL+C 专门关闭它,程序将无法在不重新启动系统的情况下再次打开.
I'm invoking a shell using Paramiko in order to use a CLI over an ssh connection. The problem with this CLI is if I do not close it specifically using CTRL+C, the program will not be able to be opened again without rebooting my system.
我尝试了以下命令:
I've tried the below commands:
SSH.send("^C\n")
SSH.send("\x003")
还有其他方法可以调用这些吗?同样,我已经使用 paramiko.SSHClient()
建立了一个 SSH 连接,然后使用 ssh.invoke_shell()
调用了一个 shell,现在我需要发送 CTRL+C 到关闭外壳的那个外壳(不是 ssh 连接)
is there another way to call these? Again, I've established an SSH connection using paramiko.SSHClient()
and then invoked a shell using ssh.invoke_shell()
and now i need to send CTRL+C to that shell to close the shell (not the ssh connection)
推荐答案
您的第二个示例在正确的轨道上,但它的格式不太正确.您实际上在那里得到了一个 2 个字符的字符串.
You're on the right track with your second example, but it isn't quite formatted right. You're actually getting a 2 character string there.
SSH.send("\x03") 应该可以解决问题.
SSH.send("\x03") should do the trick.
不过,我可能会用它来代替.
However, I'd probably have used this instead.
SSH.send(chr(3))
SSH.send(chr(3))
这篇关于Python Paramiko 将 CTRL+C 发送到 ssh shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!