Let a subprocess :func:`communicate`, then write both its ``stdout`` and
    its ``stderr`` to our ``stdout``.
323618
def print_lines(process: Popen) -> None:
    
    out, err = process.communicate()
    if out:
        for line in out.decode("utf-8").splitlines():
            print(line)
    if err:
        for line in err.decode("utf-8").splitlines():
            print(line)
413109
def run_subprocess(command):
    
    x = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
    out, err = x.communicate()
    out = out.decode('utf-8')
    err = err.decode('utf-8')
    return out, err
28958
def get_simple_output(self, stderr=STDOUT):
        
        args = shlex.split(self.cmd)
        proc = Popen(args, stdout=PIPE, stderr=stderr)
        return proc.communicate()[0].decode("utf8")
503328
def popen(*args, **kwargs):
    
    process = subprocess.Popen(*args, **kwargs)
    try:
        yield process.pid
    finally:
        os.kill(process.pid, signal.SIGTERM)
        os.waitpid(process.pid, 0)
756721
function exec(cmd, args, stdin, callback) {
            var stdout = concat();
            var stderr = concat();

            var process = child_process.spawn(cmd, args, {
                stdio: [stdin || 'ignore', 'pipe', 'pipe']
            });
            process.stdout.pipe(stdout);
            process.stderr.pipe(stderr);
            process.on('exit', function(code, signal) {
              var err;
              if (code) {
                err = new Error(code);
                err.code = code;
                err.signal = signal;
              }
              callback(err, stdout, stderr);
            });
            process.on('error', function (err) {
              callback(err, stdout, stderr);
            });
        }
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
1198972
def _handle_stderr(self, ioloop, f, count=-1):
        
        output = non_blocking_read(self._popen.stderr, count)
        if not output:
            self._popen.stderr.close()
            self._popen.stderr = None
        else:
            self._error.write(output)
            self._register_stderr(ioloop)
681701
def check_output_error_and_retcode(*popenargs, **kwargs):
    
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = subprocess.Popen(stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               *popenargs, **kwargs)
    output, error = process.communicate()
    retcode = process.poll()
    return output, error, retcode
660934
def write(self, data):
        

        self._process.poll()
        if self._process.returncode is not None:
            raise EOFError('Process ended')
        self._process.stdin.write(data)
805586
def cmd(send, _, args):
    
    with args['handler'].data_lock:
        channels = ", ".join(sorted(args['handler'].channels))
    send(channels)
1117084
def pipecmd (cmd1, cmd2):
    """"""
    p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
    p2 = subprocess.Popen(cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
    p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
    return p2.communicate()[0]
884706
def output_redirect(stdout, stderr):
  
  import sys
  import threading
  if not redirect:
    originals = (sys.stdout.write, sys.stderr.write)

    class Logger:
      def __init__(self, fun):
        self.buffer = ""
        self.fun = fun

      def logs(self):
        logs = redirect.get(threading.current_thread(), originals)[self.fun]
        # sys.__stdout__.write('hello ' + str(threading.current_thread()))
        if not isinstance(logs, (list, tuple)):
          logs = [logs]
        return logs

      def write(self, s):
        self.buffer += s
        lines = self.buffer.splitlines(keepends=True)
        last = lines[-1]
        if lines[-1][-1] != '\n':
          self.buffer = lines[-1]
          lines = lines[:-1]
        else:
          self.buffer = ""

        for line in lines:
          for log in self.logs():
            getattr(log, 'write', lambda x: log(x))(line)

      def flush_buffer(self):
        if self.buffer:
          for log in self.logs():
            getattr(log, 'write', lambda x: log(x))(self.buffer)

      def close(self):
        for log in self.logs():
          # self.flush_buffer()
          getattr(log, 'close', lambda: None)()

    lsout = Logger(0)
    sys.stdout.write = lsout.write
    sys.stdout.close = lsout.close
    lserr = Logger(1)
    sys.stderr.write = lserr.write
    sys.stderr.close = lserr.close

  # print('red ', threading.current_thread())
  thread = threading.current_thread()
  redirect.update({thread: (stdout, stderr)})
  try:
    yield
  except Exception as e:
    r = redirect.pop(thread, None)
    getattr(r, 'flush_buffer', lambda: None)()
    raise Exception(e) from e
  else:
    r = redirect.pop(thread, None)
    getattr(r, 'flush_buffer', lambda: None)()
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)
348087
def run(cmd, input=None, capture_output=False, check=False, quiet=False, **kwargs):
    """"""
    if input is not None:
        kwargs['stdin'] = subprocess.PIPE
    if capture_output:
        kwargs['stdout'] = kwargs['stderr'] = subprocess.PIPE

    try:
        proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
    except OSError as e:
        if e.errno == errno.ENOENT:
            raise ExecutableNotFound(cmd)
        else:
            raise

    out, err = proc.communicate(input)

    if not quiet and err:
        stderr_write_bytes(err, flush=True)
    if check and proc.returncode:
        raise CalledProcessError(proc.returncode, cmd, output=out, stderr=err)

    return out, err
1142590
def _run_cmd_get_output(cmd):
    
    process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
    out, err = process.communicate()
    return out or err
410806
def warn(msg, *args):
    
    if not args:
        sys.stderr.write('WARNING: ' + msg)
    else:
        sys.stderr.write('WARNING: ' + msg % args)
698266
def err_write(self, msg, **kwargs):
        
        """
        if self._thread_invalid():
            # special case: if a non-main thread writes to stderr
            # i.e. due to an uncaught exception, pass it through
            # without raising an additional exception.
            self.async_call(self.err_write, msg, **kwargs)
            return
        return self.request('nvim_err_write', msg, **kwargs)