Executes a command via ssh and sends back the exit status code.
423904
def RunCommandOnHosts(cmd, hostnames, ssh_key):
  
  if not hostnames:
    return
  p = multiprocessing.Pool(1)
  remote_command_args = [(cmd, hostname, ssh_key) for hostname in hostnames]
  #print remote_command_args
  result = None
  while not result:
    try:    
      result = p.map_async(__RemoteExecuteHelper, remote_command_args).get(999999) # allows for keyboard interrupt
    except paramiko.SSHException as e:      
      logging.info( 'failure in RunCommandOnHosts: %s' % (e))
      time.sleep(5)
    
  p.close()
  p.join()
  return result
67622
public void executeCommand(String command, Integer exitStatus, String envVar) throws Exception {
        if (exitStatus == null) {
            exitStatus = 0;
        }

        command = "set -o pipefail && alias grep='grep --color=never' && " + command;
        getRemoteSSHConnection().runCommand(command);
        setCommandResult(getRemoteSSHConnection().getResult());
        setCommandExitStatus(getRemoteSSHConnection().getExitStatus());
        runCommandLoggerAndEnvVar(exitStatus, envVar, Boolean.FALSE);

        Assertions.assertThat(getRemoteSSHConnection().getExitStatus()).isEqualTo(exitStatus);
    }
913076
def cli(ctx, cmd):
    """"""

    exit_code = util.call(cmd)
    ctx.exit(exit_code)
774660
def ExecuteCmd(cmd, quiet=False):
  
  result = None
  if quiet:
    with open(os.devnull, "w") as fnull:
      result = subprocess.call(cmd, shell=True, stdout=fnull, stderr=fnull)
  else:
    result = subprocess.call(cmd, shell=True)
  return result
943333
def execute_command(self, cmd, params=None, callback=None, raw=False):
        '''
        
        '''
        def execute_with_callbacks(cmd, params=None, callback=None, raw=False):
            code, params = self.send_command(cmd, params, raw)
            if callback:
                callback(code, params)
            return code, params

        if self.daemon:
            t = Thread(target=execute_with_callbacks,
                    args=(cmd, ), kwargs={'params':params, 'callback':callback, 'raw':raw})
            t.daemon = True
            t.start()
        else:
            return execute_with_callbacks(cmd, params, callback, raw)
19095
def _execute(params, cwd):
    

    proc = subprocess.Popen(
        params,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=cwd
    )
    stdout, stderr = proc.communicate()
    code = proc.wait()
    if code != 0:
        e = OSError('subprocess exit code for %r was %d: %s' % (params, code, stderr))
        e.stdout = stdout
        e.stderr = stderr
        raise e
    return (stdout, stderr)
490089
private void executeCommand(String command, List<String> arguments) {

        try {
            CmsShellCommandResult result = m_remoteShell.executeCommand(command, arguments);
            m_out.print(result.getOutput());
            updateState(result);
            if (m_exitCalled) {
                exit(0);
            } else if (m_hasError && (m_errorCode != -1)) {
                exit(m_errorCode);
            }
        } catch (RemoteException r) {
            r.printStackTrace(System.err);
            exit(1);
        }
    }
1092578
def send_exit_with_code(cls, sock, code):
    """"""
    encoded_exit_status = cls.encode_int(code)
    cls.send_exit(sock, payload=encoded_exit_status)
1090597
def run_checked (cmd, ret_ok=(0,), **kwargs):
    """"""
    retcode = run(cmd, **kwargs)
    if retcode not in ret_ok:
        msg = "Command `%s' returned non-zero exit status %d" % (cmd, retcode)
        raise PatoolError(msg)
    return retcode
883736
def execute(self, name, command):
        
        if name in ["localhost"]:
            r = '\n'.join(Shell.sh("-c", command).split()[-1:])
        else:
            r = '\n'.join(Shell.ssh(name, command).split()[-1:])
        return r
664267
def _exec_command(self, cmd):
        
        _, out, err = self._client.exec_command(cmd, timeout=self._timeout)
        return out.read().strip() if not err.read().strip() else None
215358
def run_command(command):
    
    try:
        check_ouput = getattr(
            subprocess, 'check_output', subprocess.check_call)
        result = check_ouput(command, stderr=subprocess.STDOUT, shell=True)
        if check_ouput.__name__ == 'check_output':
            return 0, result
        else:
            return result, None
    except subprocess.CalledProcessError as e:
        return e.returncode, getattr(e, 'output', None)
891629
def run(self, command):
        
        boto.log.debug('running:%s on %s' % (command, self.server.instance_id))
        status = 0
        try:
            t = self._ssh_client.exec_command(command)
        except paramiko.SSHException:
            status = 1
        std_out = t[1].read()
        std_err = t[2].read()
        t[0].close()
        t[1].close()
        t[2].close()
        boto.log.debug('stdout: %s' % std_out)
        boto.log.debug('stderr: %s' % std_err)
        return (status, std_out, std_err)
1267004
def execute(cmd):
    

    # Parse cmd string to a list
    if not isinstance(cmd, list):
        cmd = shlex.split(cmd)
    # Execute command
    rc = 0
    output = ""
    try:
        output = subprocess.check_output(cmd, close_fds=True,
                                         stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as err:
        rc = err.returncode
        output = err.output
    except Exception as err:
        err_msg = ('Command "%s" Error: %s' % (' '.join(cmd), str(err)))
        raise exception.SDKInternalError(msg=err_msg)

    output = bytes.decode(output)
    return (rc, output)
644278
def execute(self):
        """"""
        if self._decode_output:
            # Capture and decode system output
            with Popen(self.command, shell=True, stdout=PIPE) as process:
                self._output = [i.decode("utf-8").strip() for i in process.stdout]
                self._success = True
        else:
            # Execute without capturing output
            os.system(self.command)
            self._success = True
        return self
1171962
def execute(cls, command, shell=True):
        
        cls.debug('execute command (shell flag:%r): %r ' % (shell, command))
        try:
            check_call(command, shell=shell)
            return True
        except CalledProcessError:
            return False
171513
def execute_command(cmd, execute, echo=True):
    """"""
    if execute:
        if echo:
            print("Executing: " + cmd)
        return os.system(cmd)
    else:
        print(cmd)
        return 0