当前位置: 首页 > news >正文

微信小程序开发网站建设企业网站主页设计模板

微信小程序开发网站建设,企业网站主页设计模板,站长网站建设,wordpress 无法播放音乐我想编写一个程序(在Windows 7上的Python 3.x中),它通过ssh在远程shell上执行多个命令.在查看paramikos的exec_command()函数之后,我意识到它不适合我的用例(因为在执行命令后通道被关闭),因为命令依赖于环境变量(由先前的命令设置)并且不能连接到一个exec_command()调用,因为它…我想编写一个程序(在Windows 7上的Python 3.x中),它通过ssh在远程shell上执行多个命令.在查看paramikos的exec_command()函数之后,我意识到它不适合我的用例(因为在执行命令后通道被关闭),因为命令依赖于环境变量(由先前的命令设置)并且不能连接到一个exec_command()调用,因为它们将在程序中的不同时间执行.因此,我想在同一个通道中执行命令.我研究的下一个选项是使用paramikos的invoke_shell()函数实现交互式shellssh paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(host, usernameuser, passwordpsw, port22)channel ssh.invoke_shell()out channel.recv(9999)channel.send(cd mivne_final\n)channel.send(ls\n)while not channel.recv_ready():time.sleep(3)out channel.recv(9999)print(out.decode(ascii))channel.send(cd ..\n)channel.send(cd or_fail\n)channel.send(ls\n)while not channel.recv_ready():time.sleep(3)out channel.recv(9999)print(out.decode(ascii))channel.send(cd ..\n)channel.send(cd simulator\n)channel.send(ls\n)while not channel.recv_ready():time.sleep(3)out channel.recv(9999)print(out.decode(ascii))ssh.close()这段代码存在一些问题第一次打印并不总是打印ls输出(有时它只打印在第二次打印时).第一个cd和ls命令始终存在于输出中(我通过recv命令获取它们,作为输出的一部分),而有时会打印以下所有cd和ls命令,有时它们不会.第二个和第三个cd和ls命令(打印时)总是出现在第一个ls输出之前.我对这种“非决定论”感到困惑,非常感谢你的帮助.最佳答案import paramikoimport reclass ShellHandler:def __init__(self, host, user, psw):self.ssh paramiko.SSHClient()self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())self.ssh.connect(host, usernameuser, passwordpsw, port22)channel self.ssh.invoke_shell()self.stdin channel.makefile(wb)self.stdout channel.makefile(r)def __del__(self):self.ssh.close()def execute(self, cmd)::param cmd: the command to be executed on the remote computer:examples: execute(ls)execute(finger)execute(cd folder_name)cmd cmd.strip(\n)self.stdin.write(cmd \n)finish end of stdOUT buffer. finished with exit statusecho_cmd echo {} $?.format(finish)self.stdin.write(echo_cmd \n)shin self.stdinself.stdin.flush()shout []sherr []exit_status 0for line in self.stdout:if str(line).startswith(cmd) or str(line).startswith(echo_cmd):# up for now filled with shell junk from stdinshout []elif str(line).startswith(finish):# our finish command ends with the exit statusexit_status int(str(line).rsplit(maxsplit1)[1])if exit_status:# stderr is combined with stdout.# thus, swap sherr with shout in a case of failure.sherr shoutshout []breakelse:# get rid of coloring and formatting special charactersshout.append(re.compile(r(\x9B|\x1B\[)[0-?]*[ -/]*[-~]).sub(, line).replace(\b, ).replace(\r, ))# first and last lines of shout/sherr contain a promptif shout and echo_cmd in shout[-1]:shout.pop()if shout and cmd in shout[0]:shout.pop(0)if sherr and echo_cmd in sherr[-1]:sherr.pop()if sherr and cmd in sherr[0]:sherr.pop(0)return shin, shout, sherr
http://www.huolong8.cn/news/15498/

相关文章:

  • 做网站用什么配置的电脑云南推广
  • 网站开发小程序定制北京网站建设公司 蓝纤科技
  • 阿里云如何建立网站wordpress版08影院
  • 域名已有服务器也有怎么做网站岐山县住房和城市建设局网站
  • 做网站seo优化总结wordpress 图片cms主题
  • 建设电子商务网站需要什么设备wordpress文章无法中文
  • 医院网站建设iis7.5网站权限配置
  • php网站架设教程wordpress多用户编辑wiki
  • 深圳网站建设 外包合作wordpress代码乱吗
  • 手机wap网站制作需要多少钱常熟建设银行 招聘网站
  • wordpress做的网站吗网站制作的订单
  • 江门网站推广策划千锋教育前端培训
  • 响应式网站生成网页生成微信小程序
  • 青岛网站开发建设wordpress调用指定相关文章
  • 石家庄手机网站建设织梦网站背景音乐
  • 网站建设营销推广实训总结南宁上林网站建设
  • 爱搜索中级网站建设建设网站技术公司
  • 济南网站建设 济南货梯西安找工作哪个网站好
  • 做大型网站建设北京商场推荐
  • 安徽阜阳网站建设微信商城和网站建设
  • 南宁网站建设找建站通网站落地页怎么做
  • 人才网站建设方案做网站gzip压缩
  • 微网站内页百度推广下载安装
  • 坪洲网站建设泉州软件开发制作
  • 包装设计接单网站WordPress服务器应用镜像
  • 文山北京网站建设最好的国际贸易网站
  • 阿里巴巴国际站官网首页郑州快速建站模板
  • 大气微电影类网站织梦模板完整版登陆注册是静态网站
  • 网站弄论坛形式怎么做网站 pr
  • 宁安网站建设网络营销策划书的范文