def execute_command(self, cmd):
    #  procutils was meant to be a leaf dependency
    from sts.util.procutils import _prefix_thread
    from sts.util.procutils import color_normal
    from sts.util.procutils import color_error

    if self.cwd is not None:
      cmd = "cd " + self.cwd + " ;" + cmd

    r_stdin, r_stdout, r_stderr = self.ssh_client.exec_command(cmd)

    if self.redirect_output:
      stdout_thread = _prefix_thread(r_stdout,
                                     partial(color_normal, label=self.label))
      stderr_thread = _prefix_thread(r_stderr,
                                     partial(color_error, label=self.label))
      if self.block:
        channel = r_stdout.channel
        while True:
          if channel.recv_ready() is False and channel.exit_status_ready():
            break
      return ""
    else:
      # dealing directly with the channel makes it easier to detect exit status
      reply = ""
      channel = r_stdout.channel
      while True:
        if channel.recv_ready():
          reply += channel.recv(100)  # arbitrary
        elif channel.recv_ready() is False and channel.exit_status_ready():
          break
      channel.close()
      return reply
Execute command remotely and return the stdout results
dataset/ETHPy150Open ucb-sts/sts/sts/entities/base.py/SSHEntity.execute_command