subprocess.rb revision d00917d1449ccc5e356c9bca1de1d43b6daa4873
565N/A# A wrapper for IO.popen that returns the combined stdout and stderr.
565N/A# An exception is thrown if the subprocess exists with non-zero.
565N/Amodule Subprocess
565N/A
565N/A class Error < ::Exception
565N/A attr_reader :status, :output
565N/A def initialize(args, status, output)
565N/A super "Subprocess #{args.inspect} exited with status #{status}:\n#{output}"
565N/A @status = status
565N/A @output = output
565N/A end
565N/A end
565N/A
565N/A def self.run(*args)
565N/A output = IO.popen args, err: [:child, :out] do |ls_io|
565N/A ls_io.read
565N/A end
565N/A
565N/A status = $?.exitstatus
565N/A
565N/A if status != 0
926N/A raise Error.new args, status, output
926N/A end
835N/A
565N/A output
926N/A end
565N/A
1050N/Aend