Sha256: c7d43d9f6eae9a07dbf69c3daf1038d9048a6a07c52cec9708cfdec05dbd6716

Contents?: true

Size: 550 Bytes

Versions: 2

Compression:

Stored size: 550 Bytes

Contents

module Bash
  def self.evaluate_string script
    output = []

    Open3.popen3("bash -x -e") do |stdin, stdout, stderr, wait_thr|
      Thread.new do until (line = stdout.gets).nil? do output << [ :stdout, line ] end end
      Thread.new do until (line = stderr.gets).nil? do output << [ :stderr, line ] end end

      stdin.puts script
      stdin.puts "exit"

      wait_thr.join
    end

    output.map do |key, line|
      if key == :stderr && line =~ /^\+ (.*)/
        [:stdin, line]
      else
        [key, line]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tailog-0.7.0 lib/tailog/ext/bash.rb
tailog-0.6.9 lib/tailog/ext/bash.rb