Class: EbmSharedLib::CL

Inherits:
Object
  • Object
show all
Defined in:
lib/ebmsharedlib/utilities.rb

Class Method Summary collapse

Class Method Details

.do_cmd(cmd, dir = nil) ⇒ Object

run a command line and echo to console returns 0 on no error, otherwise the error number



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ebmsharedlib/utilities.rb', line 25

def self.do_cmd(cmd, dir=nil)
  exit_code = 0

  puts cmd
  begin
    if dir.nil? == false
      Dir.chdir(dir){
        Kernel.system(cmd)
      }
    else
      Kernel.system(cmd)
    end
  rescue Exception => ex
    exit_code = 100   #indicate an error, probably due to invalid dir
  end

  exit_code = $?.exitstatus if exit_code == 0

  exit_code
end

.do_cmd_output(cmd, dir = nil) ⇒ Object

run a command and return the output string



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ebmsharedlib/utilities.rb', line 53

def self.do_cmd_output(cmd, dir=nil)
  exit_code = 0
  result = ""

  puts cmd
  if dir.nil? == false
    Dir.chdir(dir){
      result = `#{cmd}`
    }
  else
    result = `#{cmd}`
  end

  result
end

.do_cmd_result(cmd, dir = nil) ⇒ Object

same as above but returns the result code 0 is success, anything else is an error code



48
49
50
# File 'lib/ebmsharedlib/utilities.rb', line 48

def self.do_cmd_result(cmd, dir=nil)
  do_cmd(cmd, dir)
end