Module: Kernel

Defined in:
lib/kernel.rb

Instance Method Summary collapse

Instance Method Details

#`(cmd) ⇒ Object

Override raises an error if cmd returns a non-zero exit status. Returns stdout if cmd succeeds. Note that these are simply concatenated; STDERR is not inline.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kernel.rb', line 5

def ` cmd
  stdout, stderr = ''
  
  begin
    status = Open4::popen4(cmd) do |pid, stdin_stream, stdout_stream, stderr_stream|
      stdout = stdout_stream.read
      stderr = stderr_stream.read
    end
    raise stderr.strip if !status.success?
  rescue Exception => e
    raise "'#{cmd}' failed with: '#{e.message}'"
  end
  
  return stdout
end

#system(cmd) ⇒ Object

Override raises an error if cmd returns non-zero exit status. Returns true if cmd succeeds. system!() preserves standard subshell handling (no exceptions; returns false on fail)



25
26
27
28
# File 'lib/kernel.rb', line 25

def system cmd
  `#{cmd}`
  return true
end

#system!Object



21
# File 'lib/kernel.rb', line 21

alias_method :system!, :system