Class: Vbox::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/vbox/shell.rb

Class Method Summary collapse

Class Method Details

.execute(command, options = {}) ⇒ Object

pty allows you to gradually see the output of a local command www.shanison.com/?p=415



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vbox/shell.rb', line 13

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

.execute2(command, options = {}) ⇒ Object



6
7
8
9
# File 'lib/vbox/shell.rb', line 6

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

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

.execute3(command, options = {}) ⇒ Object

occassinally fails with ‘no child processes



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vbox/shell.rb', line 30

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