我只需要启动另一个python脚本(例如:second_Python.py)在远程服务器中。这一秒_Python.py将等待来自其他服务器的某些请求。所以你只需要重新开始_Python.py返回到第一个python脚本并继续。我用下面的脚本,但脚本是挂起后开始第二_Python.py. 你知道吗
#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脚本
readlines
等待命令完成。如果不想等待,请取消呼叫。你知道吗相关问题 更多 >
编程相关推荐