Sha256: a873ddfb0936d3a4ae3d5d27ed6df03f245d2b3a49e3a8ed5a4ff2d2ca48c222
Contents?: true
Size: 735 Bytes
Versions: 7
Compression:
Stored size: 735 Bytes
Contents
require 'json' require 'open3' module SimCtl class Executor class << self def execute(command) command = command.flatten.join(' ') $stderr.puts command if ENV['SIMCTL_DEBUG'] Open3.popen3(command) do |_stdin, stdout, stderr, result| output = stdout.read if result.value.to_i > 0 output = stderr.read if output.empty? raise output end return unless block_given? if looks_like_json?(output) yield JSON.parse(output) else yield output.chomp end end end private def looks_like_json?(output) output.start_with?('[', '{') end end end end
Version data entries
7 entries across 7 versions & 1 rubygems