Bake a ``shell`` command so it's ready to execute and returns None.

        :return: None
511951
def bake(self):
        
        command_list = self.command.split(' ')
        command, args = command_list[0], command_list[1:]

        self._sh_command = getattr(sh, command)
        # Reconstruct command with remaining args.
        self._sh_command = self._sh_command.bake(
            args, _env=self.env, _out=LOG.out, _err=LOG.error)
1047544
def activation_shell_code(self, shell=None):
        """"""
        from rez.shells import create_shell
        from rez.rex import RexExecutor

        executor = RexExecutor(interpreter=create_shell(shell),
                               parent_variables=["PATH"],
                               shebang=False)
        executor.env.PATH.append(self.tools_path)
        return executor.get_output().strip()
707517
def create_process(self, command, shell=True, stdout=None, stderr=None,
                       env=None):
        
        env = env if env is not None else dict(os.environ)
        env['DISPLAY'] = self.display
        return subprocess.Popen(command, shell=shell,
                                stdout=stdout, stderr=stderr,
                                env=env)
1104664
def spawnPythonProcess(processProtocol, args=(), env={},
                       path=None, uid=None, gid=None, usePTY=0,
                       packages=()):
    
    return spawnProcess(processProtocol, sys.executable,
                        args, env, path, uid, gid, usePTY,
                        packages)
182738
def shell(args, wait=True, msg=None):
    

    # Fix Windows error if passed a string
    if isinstance(args, str):
        args = shlex.split(args, posix=(os.name != "nt"))
        if os.name == "nt":
            args = [arg.replace('/', '\\') for arg in args]

    if wait:
        proc = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        out, err = proc.communicate(input=msg)
        exitcode = proc.returncode
        if exitcode != 0:
            raise IOError(err)
        return out
    else:
        DETACHED_PROCESS = 0x00000008
        proc = Popen(args, creationflags=DETACHED_PROCESS)
1202521
def execute(self):
        
        if self._ansible_command is None:
            self.bake()

        try:
            self._config.driver.sanity_checks()
            cmd = util.run_command(
                self._ansible_command, debug=self._config.debug)
            return cmd.stdout.decode('utf-8')
        except sh.ErrorReturnCode as e:
            out = e.stdout.decode('utf-8')
            util.sysexit_with_message(str(out), e.exit_code)
221046
def execute(self, *, args: Union[list, tuple], options: dict) -> tuple:
        ''''''
        cmd = self._build_cmd(args)
        process = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE,
                                   encoding='utf-8', shell=options.get('shell', False), env=options.get('env'))
        return process
114623
def formatted_command(self):
        
        bash = self.bash
        if bash not in (None, "", NotSpecified) and callable(bash):
            bash = bash()
        if bash not in (None, "", NotSpecified):
            return "{0} -c {1}".format(self.resolved_shell, shlex_quote(bash))

        command = self.command
        if command not in (None, "", NotSpecified) and callable(command):
            command = command()
        if command not in (None, "", NotSpecified):
            return command

        return None
440662
def do(cmdline=None, runas=None):
    '''
    
    '''
    path = _pyenv_path(runas)
    cmd_split = cmdline.split()
    quoted_line = ''
    for cmd in cmd_split:
        quoted_line = quoted_line + ' ' + _cmd_quote(cmd)
    result = __salt__['cmd.run_all'](
        'env PATH={0}/shims:$PATH {1}'.format(_cmd_quote(path), quoted_line),
        runas=runas,
        python_shell=True
    )

    if result['retcode'] == 0:
        rehash(runas=runas)
        return result['stdout']
    else:
        return False
1113648
def _run_quiet(cmd,
               cwd=None,
               stdin=None,
               output_encoding=None,
               runas=None,
               shell=DEFAULT_SHELL,
               python_shell=False,
               env=None,
               template=None,
               umask=None,
               timeout=None,
               reset_system_locale=True,
               saltenv='base',
               pillarenv=None,
               pillar_override=None,
               success_retcodes=None,
               success_stdout=None,
               success_stderr=None):
    '''
    
    '''
    return _run(cmd,
                runas=runas,
                cwd=cwd,
                stdin=stdin,
                stderr=subprocess.STDOUT,
                output_encoding=output_encoding,
                output_loglevel='quiet',
                log_callback=None,
                shell=shell,
                python_shell=python_shell,
                env=env,
                template=template,
                umask=umask,
                timeout=timeout,
                reset_system_locale=reset_system_locale,
                saltenv=saltenv,
                pillarenv=pillarenv,
                pillar_override=pillar_override,
                success_retcodes=success_retcodes,
                success_stdout=success_stdout,
                success_stderr=success_stderr)['stdout']
95992
def shell_exec(command, **kwargs): # from gitapi.py
  
  proc = Popen(shlex.split(command), stdout=PIPE, stderr=PIPE, **kwargs)

  out, err = [x.decode("utf-8") for x in  proc.communicate()]

  return {'out': out, 'err': err, 'code': proc.returncode}
977869
def sh(args, **kwargs):
    
    if isinstance(args, str):
        args = args.split()
    if not args:
        return
    click.echo('$ {0}'.format(' '.join(args)))
    try:
        return subprocess.check_call(args, **kwargs)
    except subprocess.CalledProcessError as exc:
        click.secho('run error {}'.format(exc))
    except OSError as exc:
        click.secho('not found error {}'.format(exc))
860264
def bake(self):
        
        options = self.options
        default_exclude_list = options.pop('default_exclude')
        options_exclude_list = options.pop('exclude')
        excludes = default_exclude_list + options_exclude_list
        x_list = options.pop('x')

        exclude_args = ['--exclude={}'.format(exclude) for exclude in excludes]
        x_args = tuple(('-x', x) for x in x_list)
        self._ansible_lint_command = sh.ansible_lint.bake(
            options,
            exclude_args,
            sum(x_args, ()),
            self._playbook,
            _env=self.env,
            _out=LOG.out,
            _err=LOG.error)
1303219
def _run_command(cmd, options=(), env=None):
    '''
    
    '''
    params = [cmd]
    params.extend(options)
    return __salt__['cmd.run_all'](params, env=env, python_shell=False)
577491
def do_shell(self, args: argparse.Namespace) -> None:
        """"""
        import subprocess

        # Create a list of arguments to shell
        tokens = [args.command] + args.command_args

        # Support expanding ~ in quoted paths
        for index, _ in enumerate(tokens):
            if tokens[index]:
                # Check if the token is quoted. Since parsing already passed, there isn't
                # an unclosed quote. So we only need to check the first character.
                first_char = tokens[index][0]
                if first_char in constants.QUOTES:
                    tokens[index] = utils.strip_quotes(tokens[index])

                tokens[index] = os.path.expanduser(tokens[index])

                # Restore the quotes
                if first_char in constants.QUOTES:
                    tokens[index] = first_char + tokens[index] + first_char

        expanded_command = ' '.join(tokens)

        # Prevent KeyboardInterrupts while in the shell process. The shell process will
        # still receive the SIGINT since it is in the same process group as us.
        with self.sigint_protection:
            # For any stream that is a StdSim, we will use a pipe so we can capture its output
            proc = subprocess.Popen(expanded_command,
                                    stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout,
                                    stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr,
                                    shell=True)

            proc_reader = utils.ProcReader(proc, self.stdout, sys.stderr)
            proc_reader.wait()
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)
1185352
def run_command(cmd):
    
    child = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    out = [s.decode("utf-8").strip() for s in child.stdout]
    err = [s.decode("utf-8").strip() for s in child.stderr]
    w = child.wait()
    return os.WEXITSTATUS(w), out, err