diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-28 22:13:46 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-28 22:13:46 +0000 |
commit | 2fcbc7f5433fab36b60bedf5a97dd610ef231721 (patch) | |
tree | d983ddd56ecfc7aed503d1d1ab90a7cf65c48203 /lib/puppet/util.rb | |
parent | 354b945c5a023e457c22a3bd22cdfd7615a6d154 (diff) | |
download | puppet-2fcbc7f5433fab36b60bedf5a97dd610ef231721.tar.gz puppet-2fcbc7f5433fab36b60bedf5a97dd610ef231721.tar.xz puppet-2fcbc7f5433fab36b60bedf5a97dd610ef231721.zip |
Adding an "execute" method to Puppet::Util, and including the module in element.rb
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1227 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util.rb')
-rw-r--r-- | lib/puppet/util.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 50a2e1e02..2f6136ef0 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -4,6 +4,9 @@ require 'sync' require 'puppet/lock' module Puppet + # A command failed to execute. + class ExecutionFailure < RuntimeError + end module Util require 'benchmark' @@ -346,6 +349,19 @@ module Util end end + # Execute the desired command, and return the status and output. + def execute(command, failonfail = true) + output = %x{#{command}} + + if failonfail + unless $? == 0 + raise ExecutionFailure, output + end + end + + return output + end + module_function :benchmark def memory |