Sha256: 91646d354e1488f5e9f873740be2acc140339b802d68d4273971a947aee8bd37

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

require 'rexec/task'

module LSync
  
  def self.run_command(command, logger)
    logger.info "Running: #{command} in #{Dir.getwd.dump}"
    
    process_result = RExec::Task.open(command) do |task|
      task.input.close
      pipes = [task.output, task.error]

      while pipes.size > 0
        result = IO.select(pipes)

        result[0].each do |pipe|
          if pipe.closed? || pipe.eof?
            pipes.delete(pipe)
            next
          end

          if pipe == task.output
            logger.info pipe.readline.chomp
          elsif pipe == task.error
            logger.error pipe.readline.chomp
          end
        end
      end
    end
    
    return process_result
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lsync-1.2.5 lib/lsync/run.rb
lsync-1.2.1 lib/lsync/run.rb