首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >paramiko.SSHClient.exec_command挂起

paramiko.SSHClient.exec_command挂起
EN

Stack Overflow用户
提问于 2019-07-28 00:45:32
回答 1查看 319关注 0票数 0

我只需要在远程服务器上启动另一个Python脚本(例如:second_python.py)。此second_python.py将等待来自其他服务器的一些请求。因此,只需启动start_python.py并返回到第一个Python脚本,然后继续。我使用了下面的脚本,但脚本在启动second_python.py后挂起。

代码语言:javascript
复制
#First python script
import es_helper
def ConnectES(self,payload_script):
 self.es = es_helper.ESHelper(config.es_ip)      
 self.es.execute_script(config.es_script_path,config.es_script,payload_script)

#es_helper.py
def execute_command(self, cmd):
  LOG.debug("executing command '{}'".format(cmd))
  stdin, stdout, stderr = self.ssh_client.exec_command(cmd)
  return stdout.readlines(), stderr.readlines()

#This function used to start second python script
def execute_script(self,es_script_path,es_script,payload_script):
  self.execute_command('python {0}{1}{2} {0}{1}{3} > {0}{1}1.txt'.format(es_script_path,'/',es_script,es_script))


#client.py
def exec_command(
    self,
    command,
    bufsize=-1,
    timeout=None,
    get_pty=False,
    environment=None,
):

    chan = self._transport.open_session(timeout=timeout)
    if get_pty:
        chan.get_pty()
    chan.settimeout(timeout)
    if environment:
        chan.update_environment(environment)
    chan.exec_command(command)
    stdin = chan.makefile("wb", bufsize)
    stdout = chan.makefile("r", bufsize)
    stderr = chan.makefile_stderr("r", bufsize)
    return stdin, stdout, stderr

预期结果:启动第二个python脚本并返回到第一个python脚本

EN

回答 1

Stack Overflow用户

发布于 2019-07-30 15:43:22

readlines等待命令完成。如果您不想等待,请删除该呼叫。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57234161

复制
相关文章

相似问题

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