Class: CMD

Inherits:
Hash
  • Object
show all
Defined in:
lib/cmd.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, options = nil) ⇒ CMD

Returns a new instance of CMD.



9
10
11
12
13
14
15
16
17
# File 'lib/cmd.rb', line 9

def initialize(cmd, options=nil)
 initialize_defaults if(@@default_options.nil?)
 self[:output] = ''
 self[:error] = ''
 
 @@default_options.each { |key, value| self[key] = value}
 options.each { |key, value| self[key] = value} unless(options.nil?)
 self[:command]=cmd
end

Class Method Details

.default_options(hash) ⇒ Object



20
21
22
# File 'lib/cmd.rb', line 20

def self.default_options(hash)
  hash.each { |key, value| @@default_options[key] = value}
end

Instance Method Details

#executeObject



24
25
26
# File 'lib/cmd.rb', line 24

def execute
  windows_command(self, self[:command])
end

#execute_as(username) ⇒ Object



28
29
30
31
32
# File 'lib/cmd.rb', line 28

def execute_as(username)
  raise "Unsupported on operating system #{RbConfig::CONFIG["host_os"]}" unless(RbConfig::CONFIG["host_os"].include?("mingw"))
  cmd = "runas /noprofile /savecred /user:#{username} \"#{self[:command]}\""
  wait_on_spawned_process(cmd) { windows_command(self, cmd) }
end