Sha256: 25055833057e9b5daaf3d314713f62718910a72b592c930041fa0c41cc4bb858

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module Veewee
  module Util

    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 = {})
        result=ShellResult.new("","",-1)
        env.ui.info "Executing #{command}" unless options[:mute]
        escaped_command=command
        #        env.ui.info "#{escaped_command}"
        IO.popen("#{escaped_command}"+ " 2>&1") { |p|
          p.each_line{ |l|
            result.stdout+=l
            env.ui.info(l,{:new_line => false})  unless options[:mute]
          }
          result.status=Process.waitpid2(p.pid)[1].exitstatus
          if result.status!=0
            env.ui.error "Exit status was not 0 but #{result.status}" unless options[:mute]
          end
        }
        return result
      end


    end #Module
  end #Module
end #Module

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veewee-0.3.0.alpha4 lib/veewee/util/shell.rb
veewee-0.3.0.alpha3 lib/veewee/util/shell.rb
veewee-0.3.0.alpha2 lib/veewee/util/shell.rb
veewee-0.3.0.alpha1 lib/veewee/util/shell.rb