Sha256: 3fe8e59c8d0ed2e835c720300d8ed651098e8d204e08f7343082f13afee415c5
Contents?: true
Size: 628 Bytes
Versions: 8
Compression:
Stored size: 628 Bytes
Contents
require 'json' require 'open3' module SimCtl class Executor class << self def execute(command) command = command.flatten.join(' ') Open3.popen2e(command) do |_, io, result| output = io.read raise StandardError.new(output) if result.value.to_i > 0 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?('[') || output.start_with?('{') end end end end
Version data entries
8 entries across 8 versions & 1 rubygems