module Sticks::Pipe::Blocks

Public Instance Methods

capture() click to toggle source
# File lib/sticks/pipe.rb, line 14
def capture
  Proc.new { |i,o,t|
    i.close
    result = o.readlines.join("")
    Process.waitpid(t.pid) rescue nil
    result.chomp
  }
end
interactive() click to toggle source
# File lib/sticks/pipe.rb, line 41
def interactive
  Proc.new { |i,o,t|
    pid = t.pid
    ot = Thread.new {
      while !o.eof?  do
        $stdout.puts PROMPT + o.gets
      end
    }
    catch :exit do
      while !i.closed? 
        input = Readline.readline(PROMPT, true) 
        i.puts input  
        throw :exit if input == "exit"
      end
    end
    i.close
    ot.join
    t.value #Process::status
  }
end
stream(name = nil) click to toggle source
# File lib/sticks/pipe.rb, line 24
def stream name = nil
  Proc.new { |i,o,t|
    i.close
    ot = Thread.new{
      while !o.eof?  do
        $stdout.puts(name ? "[#{name}] #{o.gets}" : o.gets)
      end
    }
    ot.abort_on_exception = true
    Process.waitpid(t.pid) rescue nil
    ot.join
    Process.waitpid(t.pid) rescue nil
    t.value #Process::status
  }
end