Sha256: 554133252c9db15ea73f7f206ecfffe2ea43b0bb9300fd5299aef35e27e66ce2

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module Minke
  module Helpers
    class Shell
      def initialize logger
        @logger = logger
      end

      ##
      # Executes a shell command and returns the return status
      def execute command
        @logger.debug command
        
        require 'open3'
        cmd = 'ping www.google.com'
        Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
          while line = stdout.gets
            @logger.debug line
          end
          
          exit_status = wait_thr.value
          unless exit_status.success?
            abort "FAILED !!! #{cmd}"
          end
        end
      end

      def execute_and_return command
        log = `#{command}`
        return log.strip
      end

      def mktmpdir
        Dir.mktmpdir
      end

      def remove_entry_secure dir
        FileUtils.remove_entry_secure dir
      end

      def write_file filename, data
        File.open(filename, 'w') { |file| file.write(data) }
      end

      def read_file filename
        File.open(filename, 'rb') { |file| file.read }.strip
      end

      def exist? filename
        File.exist? filename
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
minke-1.13.4 lib/minke/helpers/shell.rb
minke-1.13.3 lib/minke/helpers/shell.rb
minke-1.13.2 lib/minke/helpers/shell.rb
minke-1.13.1 lib/minke/helpers/shell.rb
minke-1.13.0 lib/minke/helpers/shell.rb