Sha256: 043a5476ebe6a4bc073db76bc336ed9cbf8c9e66ea1c8922ab8b178cb3b821c6
Contents?: true
Size: 719 Bytes
Versions: 9
Compression:
Stored size: 719 Bytes
Contents
require 'open3' module Gitx class Executor ExecutionError = Class.new(StandardError) # execute a shell command and raise an error if non-zero exit code is returned # return the string output from the command # block argument is passed all output from the executed thread def execute(*cmd) yield "$ #{cmd.join(' ')}" if block_given? output = '' Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thread| while line = stdout_err.gets output << line yield line if block_given? end exit_status = wait_thread.value fail ExecutionError, "#{cmd.join(' ')} failed" unless exit_status.success? end output end end end
Version data entries
9 entries across 9 versions & 1 rubygems