Top Level Namespace
Defined Under Namespace
Modules: Puppetize
Instance Method Summary collapse
Instance Method Details
#cmd(command, opts = { :out => false , :err => true }) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppetize/stdlib.rb', line 2 def cmd command, opts = { :out => false , :err => true } retval = nil error = nil begin status = Open4.popen4(command) do |pid,stdin,stdout,stderr| error = stderr.read retval = stdout.read STDOUT.puts stdout if opts[:out] end rescue => e STDERR.puts "Error: #{e} #{error}" exit -1 ensure if status.exitstatus > 0 STDERR.puts "#{error}" if opts[:err] exit -1 end end retval end |