Friendly wrapper around Popen.

    Returns stdout output, stderr output and OS status code.
499669
def popen_wrapper(args):
    
    try:
        p = Popen(args,
                  shell=False,
                  stdout=PIPE,
                  stderr=PIPE,
                  close_fds=os.name != 'nt',
                  universal_newlines=True)
    except OSError as e:
        raise OSError(
            "Error executing '{:}': '{:}'".format(args[0], e.strerror))
    output, errors = p.communicate()
    return (
        output,
        text_type(errors),
        p.returncode
    )
788515
def get_output(cmd, args):
    
    from subprocess import Popen, STDOUT, PIPE

    command = [cmd]
    command.extend(listify(args))

    process = Popen(command, stdout=PIPE, stderr=STDOUT)
    out, _ = process.communicate()

    return out.decode('utf-8')
870349
def get_output(self):
        '''
        
        '''
        if not os.path.isfile(self.real_path):
            logger.debug('File %s does not exist', self.real_path)
            return

        cmd = []
        cmd.append('sed')
        cmd.append('-rf')
        cmd.append(constants.default_sed_file)
        cmd.append(self.real_path)
        sedcmd = Popen(cmd,
                       stdout=PIPE)

        if self.exclude is not None:
            exclude_file = NamedTemporaryFile()
            exclude_file.write("\n".join(self.exclude).encode('utf-8'))
            exclude_file.flush()

            cmd = "grep -v -F -f %s" % exclude_file.name
            args = shlex.split(cmd)
            proc = Popen(args, stdin=sedcmd.stdout, stdout=PIPE)
            sedcmd.stdout.close()
            stdin = proc.stdout
            if self.pattern is None:
                output = proc.communicate()[0]
            else:
                sedcmd = proc

        if self.pattern is not None:
            pattern_file = NamedTemporaryFile()
            pattern_file.write("\n".join(self.pattern).encode('utf-8'))
            pattern_file.flush()

            cmd = "grep -F -f %s" % pattern_file.name
            args = shlex.split(cmd)
            proc1 = Popen(args, stdin=sedcmd.stdout, stdout=PIPE)
            sedcmd.stdout.close()

            if self.exclude is not None:
                stdin.close()

            output = proc1.communicate()[0]

        if self.pattern is None and self.exclude is None:
            output = sedcmd.communicate()[0]

        return output.decode('utf-8', 'ignore').strip()
575456
def check_output(args, env=None, sp=subprocess):
    """"""
    log.debug('calling %s with env %s', args, env)
    output = sp.check_output(args=args, env=env)
    log.debug('output: %r', output)
    return output
329111
def check_output_and_strip(cmd):  # type: (List[Text]) -> Optional[Text]
    
    try:
        result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        return result.strip()
    except (OSError, subprocess.CalledProcessError, TypeError, AttributeError):
        # OSError is raised if command doesn't exist
        # CalledProcessError is raised if command returns nonzero
        # AttributeError is raised if result cannot be strip()ped
        return None
137155
def system(*args, **kwargs):
    """"""
    kwargs.setdefault('stdout', subprocess.PIPE)
    proc = subprocess.Popen(args, **kwargs)
    out, _ = proc.communicate()
    if proc.returncode:
        raise SystemExit(proc.returncode)
    return out.decode('utf-8')
1078996
def get_exitcode_stdout_stderr(cmd):
    
    from subprocess import Popen, PIPE
    import shlex
    args = shlex.split(cmd)

    proc = Popen(args, stdout=PIPE, stderr=PIPE)
    out, err = proc.communicate()
    exitcode = proc.returncode

    return exitcode, out, err
1054790
def check_output(args):
    
    proc = Popen(args, stdout=PIPE)
    out = proc.communicate()[0]
    if proc.returncode:
        raise CalledProcessError(proc.returncode, args, output=out)
    return out
1224372
def capture_sys_output():
    """"""
    capture_out, capture_err = StringIO(), StringIO()
    current_out, current_err = sys.stdout, sys.stderr
    try:
        sys.stdout, sys.stderr = capture_out, capture_err
        yield capture_out, capture_err
    finally:
        sys.stdout, sys.stderr = current_out, current_err
136545
def stderr(msg, silent=False):
    
    if not silent:
        print(msg, file=sys.stderr)
353698
def call_ext_prog(self, prog, timeout=300, stderr=True,
                      chroot=True, runat=None):
        
        return self.get_command_output(prog, timeout=timeout, stderr=stderr,
                                       chroot=chroot, runat=runat)
738897
def get_sys_cmd_output(cmd):
    
    _e, op = None, ''
    if not isinstance(cmd, list):
        cmd = cmd.split(' ')

    try:
        op = subprocess.check_output(cmd)
        if sys.version_info[0] >= 3:
            op = to_str(op)
        op = op.split('\n')
    except Exception as err:
        _e = err

    return _e, op
46354
def output(message, opt, extra=None):
    
    print(message, file=sys.stderr)
    if opt.verbose:
        if extra:
            print(extra)

        traceback.print_exc(sys.stderr)
851037
def print_results(cls, stdout, stderr):
        """"""
        for line in stderr:
            print(line, file=sys.stderr)
        if stdout:
            if stderr:  # blank line to separate stdout from stderr
                print(file=sys.stderr)
            cls._print_stdout(stdout)
        else:
            print(':) No issues found.')
1153613
def ossystem(cmd):
  """"""
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
                       stderr=subprocess.STDOUT)
  (stdout, stderr) = p.communicate()
  return stdout.decode('ascii')
407340
def subprocess_check_output(*args, cwd=None, env=None, stderr=False):
    

    if stderr:
        proc = yield from asyncio.create_subprocess_exec(*args, stderr=asyncio.subprocess.PIPE, cwd=cwd, env=env)
        output = yield from proc.stderr.read()
    else:
        proc = yield from asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, cwd=cwd, env=env)
        output = yield from proc.stdout.read()
    if output is None:
        return ""
    # If we received garbage we ignore invalid characters
    # it should happens only when user try to use another binary
    # and the code of VPCS, dynamips... Will detect it's not the correct binary
    return output.decode("utf-8", errors="ignore")
958888
def print_subprocess_output(subp):
    ''''''
    if subp:
        if subp.errorcode != 0:
            print('<error errorcode="%s">' % str(subp.errorcode))
            print(subp.stderr)
            print("</error>")
            print_tag('stdout', '\n%s\n' % subp.stdout)
        else:
            print_tag('success', '\n%s\n' % subp.stdout)
            print_tag('warnings', '\n%s\n' % subp.stderr)