首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python发送控件+ Q然后控制+ A(特殊键)

Python发送控件+ Q然后控制+ A(特殊键)
EN

Stack Overflow用户
提问于 2019-05-21 00:36:48
回答 2查看 0关注 0票数 0

我需要发送一些特殊的击键,并且不确定如何做到这一点。

我需要发送Ctrl+ Q后跟Ctrl+ A到终端(我正在使用Paramiko)。

我试过了

代码语言:javascript
复制
shell = client.invoke_shell()

shell.send(chr(10))
time.sleep(5)
shell.send(chr(13))

shell.send('\x11')
shell.send('\x01')

print 'i tried'

我可以看到两个返回成功,但没有,它没有退出picocom(也注意我有错误的方式回合,它期望ctrl + a,然后ctrl + q)

如果它有助于这是设备 http://www.cisco.com/c/en/us/td/docs/routers/access/interfaces/eesm/software/configuration/guide/4451_config.html#pgfId-1069760

正如你在第2步看到的那样

代码语言:javascript
复制
Step 2 Exit the session from the switch, press Ctrl-a and Ctrl-q from your keyboard:

Switch# <type ^a^q>
Thanks for using picocom
Router#

更新:

我试过\ x01 \ x16 \ x11 \ n但是这会返回

代码语言:javascript
复制
Switch#
Switch#
*** baud: 9600
*** flow: none
*** parity: none
*** databits: 8
*** dtr: down

Switch#

看起来这可能是另一个特殊命令?

EN

Stack Overflow用户

发布于 2019-05-21 09:21:26

这对我来说非常合适,完全符合我的期望。上面的代码中显然缺少一些部分,所以这需要一点翼。

代码语言:javascript
复制
import sys
import time
import getpass
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('127.0.0.1',
            username='apsuser',
            password=getpass.getpass('Password: '))
shell = ssh.invoke_shell()
shell.settimeout(0.25)

shell.send('picocom /dev/ttyS0\n')
time.sleep(2)
sys.stdout.buffer.write(shell.recv(10000))
sys.stdout.buffer.flush()

shell.send('\x01')
shell.send('\x11')

time.sleep(2)
sys.stdout.buffer.write(shell.recv(10000))
sys.stdout.buffer.flush()
print()
time.sleep(2)

结果是:

代码语言:javascript
复制
Password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Apr 14 19:55:57 2016 from 127.0.0.1
picocom /dev/ttyS0
apsuser@Steve-Laptop:~$ picocom /dev/ttyS0
picocom v1.7

port is        : /dev/ttyS0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,

Terminal ready

Thanks for using picocom
apsuser@Steve-Laptop:~$ 

那么我的代码没有做什么呢?

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100009041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档