diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/puppet/type/exec.rb | 39 | ||||
-rw-r--r-- | lib/puppet/util.rb | 16 |
2 files changed, 30 insertions, 25 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 49f3e8c4c..1c45b7b7f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -1,7 +1,5 @@ -#!/usr/local/bin/ruby -w - -# $Id$ +require 'open3' require 'puppet/type/state' module Puppet @@ -93,15 +91,30 @@ module Puppet Puppet::Util.asuser(@parent[:user], @parent[:group]) { # capture both stdout and stderr - stderr = Puppet::Util.capture_stderr { + #stdin, stdout, stderr = Open3.popen3(self.parent[:command]) + #@output = stdout.read + #err = stderr.read + + #stderr = Puppet::Util.capture_stderr { + # @output = %x{#{self.parent[:command]}} + #} + if @parent[:user] + unless defined? @@alreadywarned + Puppet.warning( + "Cannot capture STDERR when running as another user" + ) + @@alreadywarned = true + end @output = %x{#{self.parent[:command]}} - } - - if stderr != "" - stderr.split(/\n/).each { |line| - self.send(:err, line) - } + else + @output = %x{#{self.parent[:command]} 2>&1} end + + #if err != "" + # stderr.split(/\n/).each { |line| + # self.send(:err, line) + # } + #end } status = $? @@ -152,7 +165,9 @@ module Puppet @paramdoc[:path] = "The search path used for command execution. Commands must be fully qualified if no path is specified." - @paramdoc[:user] = "The user to run the command as." + @paramdoc[:user] = "The user to run the command as. Note that if you use + this then any error output is not currently captured. This is mostly + because of a bug within Ruby." @paramdoc[:group] = "The group to run the command as." @paramdoc[:cwd] = "The directory from which to run the command. If this directory does not exist, the command will fail." @@ -297,3 +312,5 @@ module Puppet end end end + +# $Id$ diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 6169bde81..e5179a587 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -19,9 +19,9 @@ module Util if group.is_a?(Integer) gid = group else - unless obj = Puppet::Type::Group[user] + unless obj = Puppet::Type::Group[group] obj = Puppet::Type::Group.create( - :name => user, + :name => group, :check => [:gid] ) end @@ -85,18 +85,6 @@ module Util return retval end - # Capture stderr of a block - def self.capture_stderr - require 'stringio' - begin - $stderr = StringIO.new - yield - $stderr.rewind && $stderr.read - ensure - $stderr = STDERR - end - end - # Create instance methods for each of the log levels. This allows # the messages to be a little richer. Most classes will be calling this # method. |