Run a command in a subprocess, given as a list of command-line
    arguments.

    Returns a ``(returncode, stdout, stderr)`` tuple.
189485
def run_cmd(cmd):
    

    try:
        p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
        # XXX: May block if either stdout or stderr fill their buffers;
        # however for the commands this is currently used for that is
        # unlikely (they should have very brief output)
        stdout, stderr = p.communicate()
    except OSError as e:
        if DEBUG:
            raise

        if e.errno == errno.ENOENT:
            msg = 'Command not found: `{0}`'.format(' '.join(cmd))
            raise _CommandNotFound(msg, cmd)
        else:
            raise _AHBootstrapSystemExit(
                'An unexpected error occurred when running the '
                '`{0}` command:\n{1}'.format(' '.join(cmd), str(e)))


    # Can fail of the default locale is not configured properly.  See
    # https://github.com/astropy/astropy/issues/2749.  For the purposes under
    # consideration 'latin1' is an acceptable fallback.
    try:
        stdio_encoding = locale.getdefaultlocale()[1] or 'latin1'
    except ValueError:
        # Due to an OSX oddity locale.getdefaultlocale() can also crash
        # depending on the user's locale/language settings.  See:
        # http://bugs.python.org/issue18378
        stdio_encoding = 'latin1'

    # Unlikely to fail at this point but even then let's be flexible
    if not isinstance(stdout, str):
        stdout = stdout.decode(stdio_encoding, 'replace')
    if not isinstance(stderr, str):
        stderr = stderr.decode(stdio_encoding, 'replace')

    return (p.returncode, stdout, stderr)
1049427
def run(command):
    
    p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
    (stdout, stderr) = p.communicate()
    return (p.returncode, [line.strip() for line in stdout.splitlines()],
            [line.strip() for line in stderr.splitlines()])
876731
def run_module_command(cmd_list, env_vars, exit_on_error=True):
    """"""
    if exit_on_error:
        try:
            subprocess.check_call(cmd_list, env=env_vars)
        except subprocess.CalledProcessError as shelloutexc:
            sys.exit(shelloutexc.returncode)
    else:
        subprocess.check_call(cmd_list, env=env_vars)
587483
def _execute_wk(*args, input=None):
    
    wk_args = (WK_PATH,) + args
    return subprocess.run(wk_args, input=input, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1195597
def _subprocess_method(self, command):
        
        p = subprocess.Popen([self._ipmitool_path] + self.args + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        self.output, self.error = p.communicate()
        self.status = p.returncode
669450
def _run(cmd, suppress_errors=False, suppress_output=False):
    
    if is_verbose():
        logger.debug('Executing: "%s"', format(cmd))
    process = subprocess.Popen(
        cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    stderr_log_level = logging.NOTSET if suppress_errors else logging.ERROR
    stdout_log_level = logging.NOTSET if suppress_output else logging.DEBUG

    stdout_thread = PipeReader(
        process.stdout, process, logger, stdout_log_level)
    stderr_thread = PipeReader(
        process.stderr, process, logger, stderr_log_level)

    stdout_thread.start()
    stderr_thread.start()

    while process.poll() is None:
        time.sleep(PROCESS_POLLING_INTERVAL)

    stdout_thread.join()
    stderr_thread.join()

    process.aggr_stdout = stdout_thread.aggr
    process.aggr_stderr = stderr_thread.aggr

    return process
447019
def run(cmd, shell=False, debug=False):
    ''
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=shell)
    (out, _) = proc.communicate()  # no need for stderr
    if debug:
        print(cmd)
        print(out)
    return out
1136258
def run_command(cmd, env=None, max_timeout=None):
    
    arglist = cmd.split()

    output = os.tmpfile()
    try:
        pipe = Popen(arglist, stdout=output, stderr=STDOUT, env=env)
    except Exception as errmsg:
        return 1, errmsg

    # Wait only max_timeout seconds.
    if max_timeout:
        start = time.time()
        while pipe.poll() is None:
            time.sleep(0.1)
            if time.time() - start > max_timeout:
                os.kill(pipe.pid, signal.SIGINT)
                pipe.wait()
                return 1, "Time exceeded"

    pipe.wait()
    output.seek(0)
    return pipe.returncode, output.read()
1142590
def _run_cmd_get_output(cmd):
    
    process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
    out, err = process.communicate()
    return out or err
959000
def popen(self, stdout, stderr):
        
        self.logger.info('Executing command: %s', self.command_str)
        return subprocess.Popen([self._executor_script], stdout=stdout, stderr=stderr)
332793
def command_run(self, command):
        
        # convert the command to sequence if a string
        if isinstance(command, basestring):
            command = shlex.split(command)
        try:
            return Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True).wait()
        except Exception as e:
            # make a pretty command for error loggings and...
            if isinstance(command, basestring):
                pretty_cmd = command
            else:
                pretty_cmd = " ".join(command)
            msg = "Command `{cmd}` {error}".format(cmd=pretty_cmd, error=e.errno)
            raise exceptions.CommandError(msg, error_code=e.errno)
1041232
def execute(self, arg_list):
        
        arg_map = self.parser.parse_args(arg_list).__dict__
        command = arg_map.pop(self._COMMAND_FLAG)
        return command(**arg_map)
770016
def run(self):
        """"""
        self.logger.debug(f'Running command: {self.cmd}')

        def execute(cmd):
            output = ""
            popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                                     universal_newlines=True, shell=True)
            for stdout_line in iter(popen.stdout.readline, ""):
                stdout_line = stdout_line.strip('\n')
                output += stdout_line
                yield stdout_line
            popen.stdout.close()
            return_code = popen.wait()
            if return_code:
                raise subprocess.CalledProcessError(return_code, cmd, output)

        try:
            for out in execute(self.cmd):
                self.logger.info(out)
            return "", 0
        except subprocess.CalledProcessError as e:
            return e.output, e.returncode
282643
def run_cmd(cmd, input=None, timeout=30, max_try=3, num_try=1):
    '''
    '''
    if type(cmd) == str:
        cmd = cmd.split()
    process = subprocess.Popen(cmd,
                               stdin=open('/dev/null', 'r'),
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    communicate_has_timeout = func_has_arg(func=process.communicate,
                                           arg='timeout')
    exception = Exception
    if communicate_has_timeout:
        exception = subprocess.TimeoutExpired  # python 3.x
    stdout = stderr = b''
    exitcode = None
    try:
        if communicate_has_timeout:
            # python 3.x
            stdout, stderr = process.communicate(input, timeout)
            exitcode = process.wait()
        else:
            # python 2.x
            if timeout is None:
                stdout, stderr = process.communicate(input)
                exitcode = process.wait()
            else:
                # thread-recipe: https://stackoverflow.com/a/4825933
                def target():
                    # closure-recipe: https://stackoverflow.com/a/23558809
                    target.out, target.err = process.communicate(input)
                import threading
                thread = threading.Thread(target=target)
                thread.start()
                thread.join(timeout)
                if thread.is_alive():
                    process.terminate()
                    thread.join()
                    exitcode = None
                else:
                    exitcode = process.wait()
                stdout = target.out
                stderr = target.err
    except exception:
        if num_try < max_try:
            return run_cmd(cmd, input, timeout, max_try, num_try+1)
        else:
            return CmdResult(exitcode, stdout, stderr, cmd, input)
    return CmdResult(exitcode, stdout, stderr, cmd, input)
591907
def runCommandReturnOutput(cmd):
    
    splits = shlex.split(cmd)
    proc = subprocess.Popen(
        splits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if proc.returncode != 0:
        raise subprocess.CalledProcessError(stdout, stderr)
    return stdout, stderr
672930
def call_out(command):
  
  # start external command process
  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  # get outputs
  out, _ = p.communicate()

  return p.returncode, out.strip()
1263550
def run_command(self, args):
        
        parsed_args = self.parser.parse_args(args)
        if hasattr(parsed_args, 'func'):
            parsed_args.func(parsed_args)
        else:
            self.parser.print_help()