Sha256: e9306a98f57d3114d0c06f44907ec7555b571537a829c6575cb8d6136684daa8

Contents?: true

Size: 599 Bytes

Versions: 4

Compression:

Stored size: 599 Bytes

Contents

require 'open3'
require 'thor/shell'

module Execution

  Thread.abort_on_exception = true

  def threadexec(command, prefix = nil, color = nil)

    if prefix.nil?
      # TODO: probably pick the command name without args
      prefix = 'unknown'
    end

    if color.nil?
      color = :cyan
    end

    Thread.new {
      Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|

        while lineOut = stdout.gets
          say_status prefix, lineOut, color
        end

        while lineErr = stderr.gets
          say_status prefix, lineErr, :red
        end

      end
    }

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
docker-sync-0.0.11 lib/execution.rb
docker-sync-0.0.9 lib/execution.rb
docker-sync-0.0.8 lib/execution.rb
docker-sync-0.0.7 lib/execution.rb