Redirect stdout and stderr back to screen.
175941
def unredirect_stdout(self):
        """"""
        if hasattr(self, 'hijacked_stdout') and hasattr(self, 'hijacked_stderr'):
            sys.stdout = self.hijacked_stdout
            sys.stderr = self.hijacked_stderr
211390
async def stderr_handler(self, line):
        

        await self.queue.put(self.clean_bytes(b'[stderr] ' + line))
890702
def Exit(msg, code=1):
    
    print >> sys.stderr, msg
    sys.exit(code)
805653
def safe_main():
    """"""
    try:
        main()
    except KeyboardInterrupt:
        logger.info("Cancelled by user")
        sys.exit(0)
    except ProgramError as e:
        logger.error(e.message)
        parser.error(e.message)
277538
def handle_stderr(stderr_pipe):
    
    stderr_output = stderr_pipe.read()

    if len(stderr_output) > 0:
        click.secho("\n__ Error Output {0}".format('_'*62), fg='white',
                    bold=True)
        click.echo(stderr_output)

    return True
331970
def stderr_output(cmd):
    """"""

    handle, gpg_stderr = stderr_handle()
    try:
        output = subprocess.check_output(cmd, stderr=gpg_stderr)  # nosec
        if handle:
            handle.close()

        return str(polite_string(output))
    except subprocess.CalledProcessError as exception:
        LOGGER.debug("GPG Command %s", ' '.join(exception.cmd))
        LOGGER.debug("GPG Output %s", exception.output)
        raise CryptoritoError('GPG Execution')
653014
def barf(msg, exit=None, f=sys.stderr):
    ''''''
    exit = const('FSQ_FAIL_TMP') if exit is None else exit
    shout(msg, f)
    sys.exit(exit)
1126712
def block(self):
        """"""
        if self._uses_subprocess:
            # consume stdout and stderr
            if self.blocking:
                try:
                    stdout, stderr = self.subprocess.communicate()
                    self.__out = stdout
                    self.__err = stderr
                except ValueError:
                    pass  # Don't read from finished subprocesses.
            else:
                self.subprocess.stdin.close()
                self.std_out.close()
                self.std_err.close()
                self.subprocess.wait()
        else:
            self.subprocess.sendeof()
            try:
                self.subprocess.wait()
            finally:
                if self.subprocess.proc.stdout:
                    self.subprocess.proc.stdout.close()
458383
def launch(program, sock, stderr=True, cwd=None, env=None):
        
        if stderr is True:
            err = sock # redirect to socket
        elif stderr is False:
            err = open(os.devnull, 'wb') # hide
        elif stderr is None:
            err = None # redirect to console

        p = subprocess.Popen(program,
                shell=type(program) not in (list, tuple),
                stdin=sock, stdout=sock, stderr=err,
                cwd=cwd, env=env,
                close_fds=True)

        sock.close()
        return p
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
874590
def stderr_with_input(cmd, stdin):
    """"""
    handle, gpg_stderr = stderr_handle()
    LOGGER.debug("GPG command %s", ' '.join(cmd))
    try:
        gpg_proc = subprocess.Popen(cmd,  # nosec
                                    stdout=subprocess.PIPE,
                                    stdin=subprocess.PIPE,
                                    stderr=gpg_stderr)

        output, _err = gpg_proc.communicate(polite_bytes(stdin))

        if handle:
            handle.close()

        return output
    except subprocess.CalledProcessError as exception:
        return gpg_error(exception, 'GPG variable encryption error')
    except OSError as exception:
        raise CryptoritoError("File %s not found" % exception.filename)
1311525
def call(args, stdout=PIPE, stderr=PIPE):
    
    p = Popen(args, stdout=stdout, stderr=stderr)
    out, err = p.communicate()

    try:
        return out.decode(sys.stdout.encoding), err.decode(sys.stdout.encoding)
    except Exception:
        return out, err
1268845
def out(msg, error=False):
        "  "
        pipe = stdout
        if error:
            pipe = stderr
            msg = color_msg(msg, "warning")

        pipe.write("%s\n" % msg)
763009
def main() -> None:
    """"""
    try:
        _real_main()
    except GuesslangError as error:
        LOGGER.critical("Failed: %s", error)
        sys.exit(-1)
    except KeyboardInterrupt:
        LOGGER.critical("Cancelled!")
        sys.exit(-2)
1082795
def stderr_redirected(to=os.devnull):
    
    fd = sys.stderr.fileno()

    # assert that Python and C stdio write using the same file descriptor
    # assert libc.fileno(ctypes.c_void_p.in_dll(libc, "stderr")) == fd == 1
    
    def _redirect_stderr(to):
        sys.stderr.close()  # + implicit flush()
        os.dup2(to.fileno(), fd)  # fd writes to 'to' file
        sys.stderr = os.fdopen(fd, 'w')  # Python writes to fd

    with os.fdopen(os.dup(fd), 'w') as old_stderr:
        with open(to, 'w') as file:
            _redirect_stderr(to=file)
        try:
            yield  # allow code to be run with the redirected stderr
        finally:
            _redirect_stderr(to=old_stderr)
939636
def report_stderr(host, stderr):
    
    lines = stderr.readlines()
    if lines:
        print("STDERR from {host}:".format(host=host))
        for line in lines:
            print(line.rstrip(), file=sys.stderr)
275574
def send_stderr(cls, sock, payload):
    """"""
    cls.write_chunk(sock, ChunkType.STDERR, payload)