Manages reading from the stdout and stderr streams

   * stdout_stream: The process' stdout stream
   * stderr_stream: The process' stderr stream
   * block:         The block to pass output to (optional)
354918
def handle_streams(stdout_stream, stderr_stream, &block)
        logger.debug "Monitoring stdout/stderr streams for output"
        streams = [stdout_stream, stderr_stream]
        until streams.empty?
          # Find which streams are ready for reading, timeout 0.1s
          selected, = select(streams, nil, nil, 0.1)

          # Try again if none were ready
          next if selected.nil? or selected.empty?

          selected.each do |stream|
            if stream.eof?
              logger.debug "Stream reached end-of-file"
              if @success.nil?
                logger.debug "Process hasn't finished, keeping stream"
              else
                logger.debug "Removing stream"
                streams.delete(stream)
              end
              next
            end

            while data = @reader.call(stream)
              data = ((@options[:mode] == :chars) ? data.chr : data)
              stream_name = (stream == stdout_stream) ? :stdout : :stderr
              output data, stream_name, &block unless block.nil?
              buffer data, stream_name unless @options[:no_buffer]
            end
          end
        end
      end
544305
def go(&stream_block)
      @status = :running
      @results = { @host.hostname => {} }
      mktemp = exec_and_log(@host, "mktemp -d -t '#{@template}'", @sudo, @results[@host.hostname], &stream_block)

      if (mktemp[:exit_status]).zero?
        @dir = mktemp[:stdout].strip
        exec_and_log(@host, "chmod #{@chmod} #{@dir}", @sudo, @results[@host.hostname], &stream_block)
      end

      @results
    end
220746
function(err,results) {
                            var _stdout = fs.createReadStream(results[1]);
                            var _stderr = fs.createReadStream(results[0]);
                            jobObj.emit("completed", _stdout, _stderr, jobObj);
                        }
334728
def write_to_stream(stream, response, block_len=1024):
        
        try:
            i_start = 0
            i_end = block_len
            while True:
                if i_end > len(response):
                    stream(response[i_start:])
                    break
                stream(response[i_start:i_end])
                i_start = i_end
                i_end += block_len
        except (socket.timeout, socket.error) as exception:
            logger.debug('Error sending response to the client: %s', exception)
762460
def print_live_output(self):
        '''
        
        '''
        if self.block:
            raise TypeError(NON_BLOCKING_ERROR_MESSAGE)
        else:
            while self.thread.is_alive() or self.old_output_size < len(self.output) or self.old_error_size < len(self.error):
                if self._stdout is not None and len(self.output) > self.old_output_size:
                    while self.old_output_size < len(self.output):
                        self.logger.info(self.output[self.old_output_size])
                        self.old_output_size += 1

                if self._stderr is not None and len(self.error) > self.old_error_size:
                    while self.old_error_size < len(self.error):
                        self.logger.error(self.error[self.old_error_size])
                        self.old_error_size += 1
990035
def redirect_stderr(self, enabled=True, log_level=logging.ERROR):
        
        if enabled:
            if self.__stderr_wrapper:
                self.__stderr_wrapper.update_log_level(log_level=log_level)
            else:
                self.__stderr_wrapper = StdErrWrapper(logger=self, log_level=log_level)

            self.__stderr_stream = self.__stderr_wrapper
        else:
            self.__stderr_stream = _original_stderr

        # Assign the new stream to sys.stderr
        sys.stderr = self.__stderr_stream
369684
def process_block(self, block):
        
        ret = []
        output = None
        input_lines = None
        lineno = self.IP.execution_count

        input_prompt = self.promptin % lineno
        output_prompt = self.promptout % lineno
        image_file = None
        image_directive = None

        for token, data in block:
            if token == COMMENT:
                out_data = self.process_comment(data)
            elif token == INPUT:
                (out_data, input_lines, output, is_doctest, decorator,
                    image_file, image_directive) = \
                          self.process_input(data, input_prompt, lineno)
            elif token == OUTPUT:
                out_data = \
                    self.process_output(data, output_prompt,
                                        input_lines, output, is_doctest,
                                        decorator, image_file)
            if out_data:
                ret.extend(out_data)

        # save the image files
        if image_file is not None:
            self.save_image(image_file)

        return ret, image_directive
182551
def _log_to_stderr(self, record):
    
    # emit() is protected by a lock in logging.Handler, so we don't need to
    # protect here again.
    old_stream = self.stream
    self.stream = sys.stderr
    try:
      super(PythonHandler, self).emit(record)
    finally:
      self.stream = old_stream
147392
def get_stream_handler(stream=sys.stderr, level=logging.INFO,
                       log_format=log_formats.easy_read):
    
    sh = logging.StreamHandler(stream)
    sh.setLevel(level)
    sh.setFormatter(logging.Formatter(log_format))
    return sh
574735
def output_thread(log, stdout, stderr, timeout_event, is_alive, quit,
        stop_output_event):
    

    poller = Poller()
    if stdout is not None:
        poller.register_read(stdout)
    if stderr is not None:
        poller.register_read(stderr)

    # this is our poll loop for polling stdout or stderr that is ready to
    # be read and processed.  if one of those streamreaders indicate that it
    # is done altogether being read from, we remove it from our list of
    # things to poll.  when no more things are left to poll, we leave this
    # loop and clean up
    while poller:
        changed = no_interrupt(poller.poll, 0.1)
        for f, events in changed:
            if events & (POLLER_EVENT_READ | POLLER_EVENT_HUP):
                log.debug("%r ready to be read from", f)
                done = f.read()
                if done:
                    poller.unregister(f)
            elif events & POLLER_EVENT_ERROR:
                # for some reason, we have to just ignore streams that have had an
                # error.  i'm not exactly sure why, but don't remove this until we
                # figure that out, and create a test for it
                pass

        if timeout_event and timeout_event.is_set():
            break

        if stop_output_event.is_set():
            break

    # we need to wait until the process is guaranteed dead before closing our
    # outputs, otherwise SIGPIPE
    alive, _ = is_alive()
    while alive:
        quit.wait(1)
        alive, _ = is_alive()

    if stdout:
        stdout.close()

    if stderr:
        stderr.close()
502976
def stderr(self):
        
        streams = self._payload.get('streams', None)
        return streams[1] if streams is not None and len(streams) >= 2 else ''
1229273
function(options) {
			this.inputStream = options.inputStream || process.stdin;
			this.outputStream = options.outputStream || process.stdout;
		}
971350
def get_complex_output(self, stderr=STDOUT):
        
        proc = Popen(self.cmd, shell=True, stdout=PIPE, stderr=stderr)
        return proc.stdout.readlines()
248633
function streamResultsPromise (command, args, options, cb) {
    var output = ''
    var stderr = ''
    var child = spawn(command, args, options)
    child.stdout.setEncoding('utf8')
    child.stderr.setEncoding('utf8')
    child.stdout.on('data', stdoutHandler)
    child.stderr.on('data', stderrHandler)
    child.on('close', closeHandler)

    function stdoutHandler (data) {
      output += data
    }

    function stderrHandler (data) {
      stderr += data
    }

    function closeHandler (code) {
      if (code !== 0) {
        var ex = new Error('pdf-text-extract command failed: ' + stderr)
        throw ex
      }
      cb(output)
    }
  }
390380
def stdout(self):
        
        streams = self._payload.get('streams', None)
        return streams[0] if streams is not None and len(streams) >= 1 else ''
1141103
def execute &block
      raise 'Previous process still exists' unless pipes.empty?

      # clear callbacks
      @callbacks = []
      @errbacks = []

      pid, stdin, stdout, stderr = POSIX::Spawn.popen4 @command.to_s

      @pid = pid
      @stdin  = attach_pipe_handler :stdin, stdin
      @stdout = attach_pipe_handler :stdout, stdout
      @stderr = attach_pipe_handler :stderr, stderr

      if block
        block.call self
      elsif @execution_proc
        @execution_proc.call self
      end
      self
    end
535923
function stream(opts) {
  opts = lo.isObject(opts) ? opts : {}
  config.input = opts.input || process.stdin
  config.output = opts.output || process.stdout
}