Sha256: e8acc9092f0fb2ab0a005fea0c1895cfe84eeec558374ab60f28ff029fc2eba6

Contents?: true

Size: 1.86 KB

Versions: 12

Compression:

Stored size: 1.86 KB

Contents

module Veewee
  module Provider
    module Core
      module Helper

        class ShellResult
          attr_accessor :stdout
          attr_accessor :stderr
          attr_accessor :status

          def initialize(stdout,stderr,status)
            @stdout=stdout
            @stderr=stderr
            @status=status
          end
        end

        module Shell

          # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185404
          # This should work on windows too now
          # This will result in a ShellResult structure with stdout, stderr and status
          def shell_exec(command,options = {:mute => true,:status => 0})
            defaults={:mute => true, :status => 0}
            options=defaults.merge(options)
            result=ShellResult.new("","",-1)
            ui.info "Executing #{command}" unless options[:mute]
            env.logger.debug "Command: \"#{command}\""
            env.logger.debug "Output:"
            env.logger.debug "-------"
            escaped_command=command
            IO.popen("#{escaped_command}"+ " 2>&1") { |p|
              p.each_line{ |l|
                result.stdout+=l
                ui.info(l,{:new_line => false})  unless options[:mute]
                env.logger.debug(l.chomp)
              }
              result.status=Process.waitpid2(p.pid)[1].exitstatus
              if result.status.to_i!=options[:status]
                ui.error "Error: We executed a shell command and the exit status was not #{options[:status]}"
                ui.error "- Command :#{command}."
                ui.error "- Exitcode :#{result.status}."
                ui.error "- Output   :\n#{result.stdout}"
                raise Veewee::Error,"Wrong exit code for command #{command}"
              end
            }
            return result
          end


        end #Module
      end #Module
    end #Module
  end #Module
end #Module

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
veewee-0.3.7 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.6 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.5 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.4 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.3 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.2 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.1 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.0.beta2 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.0.beta1 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.0.alpha9 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.0.alpha8 lib/veewee/provider/core/helper/shell.rb
veewee-0.3.0.alpha7 lib/veewee/provider/core/helper/shell.rb