当前位置: 首页 > 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.zqtcl.cn/news/39397/

相关文章:

  • 网站建设带主机公明网站制作
  • 长春做网站优化价格广州市越秀区建设局官方网站
  • 牛什么的网站建设注册公司分类大全
  • 教育培训网站设计深圳网站建设服务平台
  • 湖北山河建设集团网站网站中的二维码设计
  • 淘宝上 网站建设美点网络公司网站
  • 一键网站制作appseo新方法
  • 平顶山住房和城乡建设局网站wordpress 字母
  • 家装网站建设哪家好点如何做免费网站
  • 如何做网站的网页张家界建设局网站
  • 域联网站建设建设银行的网站
  • 网站设计制作报告公路建设市场信用信息系统网站
  • 西安网站公司建设一个空间两个网站
  • 杭州品格网站设计世界摄影网站
  • 校园交友的网站建设做网站用什么系统较好
  • ...东莞网站公司网站建设+网络科技公司
  • 淘宝客返利网站建设海报设计分析
  • 百度seo怎么提高排名宁波网站建设优化企业
  • 网站备案关闭影响排名苏州品牌网站设计
  • 手机网站做多宽的图片wordpress浮动菜单
  • 从用户角度网站应该具备的条件养老院为什么要建设网站
  • 张掖北京网站建设泉州seo网络营销
  • 上线啦 图谱智能网站深圳工程招标交易网
  • 电子商务网站建设课设心得体会wordpress 去掉页脚
  • 广州企业建站系统模板c 新手一个人做网站
  • dedecms公司网站怎么做网站建设div可拖拽布局
  • 万家建设有限公司网站网络规划与设计论文开题报告
  • 内蒙古兴安盟建设局网站福安建设厅网站
  • 环保网站 中企动力建设二级域名著名网站
  • i岗网站建设个人开发app可以上架吗