Executes shell command in a given working_directory.
    Command is a list of strings to execute as a command line.
    Returns a tuple of two byte strings: (stdout, stderr)
338034
def call(command, working_directory=config.BASE_DIR):
    
    LOG.info(command)
    proc = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE, cwd=working_directory, shell=True)
    out, err = proc.communicate()
    return (out, err)
12344
def _execute_commands_from_dir(self, directory):
        """"""
        # Get file paths and contents
        commands = get_commands_from_dir(directory)

        # Execute failed commands again
        print('\tAttempting to execute {0} failed commands'.format(len(commands)))
        return self.execute(commands, ignored_commands=None, execute_fails=True)
563005
def _runcmd(progargs, stdinput=None):
    '''
    
    '''
    stdin = None
    if stdinput is not None:
        assert(isinstance(stdinput, list))
        stdin=PIPE

    err = 0
    output = b''
    log_debug("Calling {} with input {}".format(' '.join(progargs), stdinput))
    try:
        p = Popen(progargs, shell=True, stdin=stdin, 
            stderr=STDOUT, stdout=PIPE, universal_newlines=True)
        if stdinput is not None:
            for cmd in stdinput:
                print(cmd, file=p.stdin)
            p.stdin.close()
        output = p.stdout.read()
        p.stdout.close()
        err = p.wait(timeout=1.0)
    except OSError as e:
        err = e.errno
        log_warn("Error calling {}: {}".format(progargs, e.stderror))
    except Exception as e:
        errstr = str(e)
        log_warn("Error calling {}: {}".format(progargs, errstr))
        err = -1
    log_debug("Result of command (errcode {}): {}".format(err, output))
    return err,output
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
939201
def _do_exec(self, cmd, args):
        
        if not args:
            self.stderr.write("execute: empty command\n")
            return
        proc = subprocess.Popen(subprocess.list2cmdline(args),
                shell = True, stdout = self.stdout)
        proc.wait()
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
115173
def shell(self, command, *args, environment=None):
        
        command += ' ' + ' '.join(args)
        command = command.strip()
        self.debug(self.yellow_style('$ %s' % command))
        env = self.env.copy()
        env.update(environment or {})
        return subprocess.call(command, shell=True, env=env)
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)
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)
853813
def execute_cmd(cmd, **kwargs):
    
    yield '$ {}\n'.format(' '.join(cmd))
    kwargs['stdout'] = subprocess.PIPE
    kwargs['stderr'] = subprocess.STDOUT

    proc = subprocess.Popen(cmd, **kwargs)

    # Capture output for logging.
    # Each line will be yielded as text.
    # This should behave the same as .readline(), but splits on `\r` OR `\n`,
    # not just `\n`.
    buf = []
    def flush():
        line = b''.join(buf).decode('utf8', 'replace')
        buf[:] = []
        return line

    c_last = ''
    try:
        for c in iter(partial(proc.stdout.read, 1), b''):
            if c_last == b'\r' and buf and c != b'\n':
                yield flush()
            buf.append(c)
            if c == b'\n':
                yield flush()
            c_last = c
    finally:
        ret = proc.wait()
        if ret != 0:
            raise subprocess.CalledProcessError(ret, cmd)
591003
def shellne(command):
    

    child = os.popen(command)
    data = child.read()
    err = child.close()
    if err:
        raise RuntimeError('%s failed w/ exit code %d' % (command, err))
    return data
408579
def execute_command(self, command):
        

        self.info_log("executing command: %s" % command)

        try:
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

            k = paramiko.RSAKey.from_private_key_file(
                self.browser_config.get('ssh_key_path')
            )
            ssh.connect(
                self.private_ip,
                username=self.browser_config.get('username'),
                pkey=k
            )

            sleep_time = 0.1
            stdout = []
            stderr = []

            ssh_transport = ssh.get_transport()
            channel = ssh_transport.open_session()
            channel.setblocking(0)
            channel.exec_command(command)

            while True:

                while channel.recv_ready():
                    stdout.append(channel.recv(1000))

                while channel.recv_stderr_ready():
                    stderr.append(channel.recv_stderr(1000))

                if channel.exit_status_ready():
                    break

                sleep(sleep_time)

            # ret = channel.recv_exit_status()
            ssh_transport.close()

            ssh.close()

            return b''.join(stdout), b''.join(stderr)

        except Exception as e:
            msg = "Execute_command exception: %s" % str(e)
            self.error_log(msg)
            raise Exception(msg)
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
995595
def execute_command(command=None):
    """"""
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stdin = process.communicate()
    process.wait()
    return (stdout, stdin), process.returncode
958129
def do_execute(self):
        
        directory = str(self.resolve_option("dir"))
        if not os.path.exists(directory):
            return "Directory '" + directory + "' does not exist!"
        if not os.path.isdir(directory):
            return "Location '" + directory + "' is not a directory!"
        collected = []
        result = self._list(directory, collected)
        if result is None:
            for c in collected:
                self._output.append(Token(c))
        return result
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
830638
def _execute(self, *args):
        
        command = (
            [
                'task',
                'rc:%s' % self.config_filename,
            ]
            + self.get_configuration_override_args()
            + [six.text_type(arg) for arg in args]
        )

        # subprocess is expecting bytestrings only, so nuke unicode if present
        # and remove control characters
        for i in range(len(command)):
            if isinstance(command[i], six.text_type):
                command[i] = (
                    taskw.utils.clean_ctrl_chars(command[i].encode('utf-8')))

        try:
            proc = subprocess.Popen(
                command,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            stdout, stderr = proc.communicate()
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise OSError("Unable to find the 'task' command-line tool.")
            raise

        if proc.returncode != 0:
            raise TaskwarriorError(command, stderr, stdout, proc.returncode)

        # We should get bytes from the outside world.  Turn those into unicode
        # as soon as we can.
        # Everything going into and coming out of taskwarrior *should* be
        # utf-8, but there are weird edge cases where something totally unusual
        # made it in.. so we need to be able to handle (or at least try to
        # handle) whatever.  Kitchen tries its best.
        try:
            stdout = stdout.decode(self.config.get('encoding', 'utf-8'))
        except UnicodeDecodeError as e:
            stdout = kitchen.text.converters.to_unicode(stdout)
        try:
            stderr = stderr.decode(self.config.get('encoding', 'utf-8'))
        except UnicodeDecodeError as e:
            stderr = kitchen.text.converters.to_unicode(stderr)

        # strip any crazy terminal escape characters like bells, backspaces,
        # and form feeds
        for c in ('\a', '\b', '\f', ''):
            stdout = stdout.replace(c, '?')
            stderr = stderr.replace(c, '?')

        return stdout, stderr