Class: EbmSharedLib::CL
- Inherits:
-
Object
- Object
- EbmSharedLib::CL
- Defined in:
- lib/ebmsharedlib/utilities.rb
Class Method Summary collapse
-
.do_cmd(cmd, dir = nil) ⇒ Object
run a command line and echo to console returns 0 on no error, otherwise the error number.
-
.do_cmd_ignore_str(cmd, ok_match, dir = nil) ⇒ Object
run a command and don’t consider it an error if output contains string.
-
.do_cmd_output(cmd, dir = nil) ⇒ Object
run a command and return the output string.
-
.do_cmd_result(cmd, dir = nil) ⇒ Object
same as above but returns the result code 0 is success, anything else is an error code.
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_ignore_str(cmd, ok_match, dir = nil) ⇒ Object
run a command and don’t consider it an error if output contains string
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ebmsharedlib/utilities.rb', line 71 def self.do_cmd_ignore_str(cmd, ok_match, dir=nil) msg = EbmSharedLib::CL.do_cmd_output(cmd, dir) puts msg exit_code = $?.exitstatus if exit_code != 0 line = msg.split("\n").last # last line # ugly hack to not show as error when nothing to commit if !line.nil? && line.include?(ok_match) exit_code = 999 end end 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 |