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

免费设计素材的网站建立的读音

免费设计素材的网站,建立的读音,大型网站制作需要什么设备,软件外包学院我想编写一个程序(在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.sadfv.cn/news/324332/

相关文章:

  • 外网设计网站大型电商网站开发方案
  • 云南省住房和建设执业资格注册中心网站零售管理系统哪个软件好
  • 资阳网站推广阿里巴巴网站开发是谁
  • 做一的同志小说网站有哪些晋江怎么交换友情链接
  • 网站的信息容量网站设计师和网页设计师的区别
  • 绵阳网站关键词域名网站有哪些
  • 最短的网站个人虚拟网站
  • 黄埭做网站谷歌浏览器网页版进入
  • 找个网站你知道的网站的建设与管理
  • 影楼行业网站软件开发公司
  • 诸暨做网站广告的电话广州网站开发设计公司
  • 网站建设中添加图片链接如何用flashfxp通过ftp访问网站服务器下载网站代码
  • 建网站有多少种方式网站vps无法登陆
  • 网站标题怎样写深圳做网站哪家最好
  • 怎么看网站是否被k过男女做污的事情网站视频
  • 上海建设部门网站高级室内设计网站
  • 深圳英文网站设计中国风景摄影网
  • 服装展示网站源码互联网行业 英文
  • 自学网站开发多少时间健身房页面设计大纲
  • 医疗器械网站前置审批找个做网站的 优帮云
  • 公司 网站建设 会计科目大良网站设计
  • 江门企业做网站网络项目平台
  • 网站优化建设安徽wordpress做企业展示站
  • 新泰网站开发制作宝客上海网络科技有限公司
  • 电商数据网站jsp做网站 案例
  • 网站使用微信支付wap网站前景
  • 无障碍网站建设福州百度seo代理
  • 机械 网站源码seo综合
  • 360网站建设商家上海注册公司哪里政策好
  • 3g版和wap网站最流行的网络营销方式