Module: CertWatch::Shell

Extended by:
Shell
Included in:
Shell
Defined in:
lib/cert_watch/shell.rb

Defined Under Namespace

Classes: CommandFailed

Instance Method Summary collapse

Instance Method Details

#sudo(command) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cert_watch/shell.rb', line 7

def sudo(command)
  output, input = IO.pipe
  prefix = !Rails.env.test? ? 'sudo ' : ''
  full_command = [prefix, command].join

  result = system(full_command, [:out, :err] => input)
  input.close

  unless result
    fail(CommandFailed, "Command '#{full_command}' failed with output:\n\n#{output.read}\n")
  end
end