Sha256: 03b5d53a13b660e0ac36ae371832b1bc1d65773fe33ddcdb4c89c035fdd1780f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#require 'open4'

module Vbox
  class Shell

    def self.execute2(command,options = {})

      IO.popen("#{command}") { |f| print f }
    end

    #pty allows you to gradually see the output of a local command
    #http://www.shanison.com/?p=415
    def self.execute(command, options = {} )
      require "pty"
      begin
        PTY.spawn( command ) do |r, w, pid|
          begin
            r.each { }
            #r.each { |line| print line;}

          rescue Errno::EIO
          end
        end
      rescue PTY::ChildExited => e
        puts "The child process exited!"
      end
    end

    #occassinally fails with 'no child processes
    def self.execute3(command, options = {} )
      defaults= { :port => "22", :exitcode => "0", :user => "root"}
      options=defaults.merge(options)

      status = POpen4::popen4(command) do |stdout,stderr,stdin|
        stdout.each do |line|
          puts line
        end
      end

      @status=status.to_i

      if (@status.to_s != options[:exitcode] )
        if (options[:exitcode]=="*")
          #its a test so we don't need to worry
        else
          raise "Exitcode was not what we expected"
        end

      end

    end

  end #Class
end #Module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vbox-0.0.4 lib/vbox/shell.rb