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
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
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)