diff options
Diffstat (limited to 'gems/gitlab-housekeeper/lib/gitlab/housekeeper/shell.rb')
-rw-r--r-- | gems/gitlab-housekeeper/lib/gitlab/housekeeper/shell.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/shell.rb b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/shell.rb new file mode 100644 index 00000000000..ed51073f0ed --- /dev/null +++ b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/shell.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'open3' + +module Gitlab + module Housekeeper + class Shell + Error = Class.new(StandardError) + + def self.execute(*cmd) + stdin, stdout, stderr, wait_thr = Open3.popen3(*cmd) + + stdin.close + out = stdout.read + stdout.close + err = stderr.read + stderr.close + + exit_status = wait_thr.value + + raise Error, "Failed with #{exit_status}\n#{out}\n#{err}\n" unless exit_status.success? + + out + err + end + end + end +end |