From d32d7f30f672e59c1427d9dfe32e7b7be35a48ab Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 19 Nov 2008 18:44:41 +1100 Subject: Fixed #1752 - Add an optional argument to Puppet::Util.execute to determine whether stderr and stdout are combined in the output --- lib/puppet/util.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 59f732dae..09c94c3c9 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -268,7 +268,7 @@ module Util # Execute the desired command, and return the status and output. # def execute(command, failonfail = true, uid = nil, gid = nil) - def execute(command, arguments = {:failonfail => true}) + def execute(command, arguments = {:failonfail => true, :combine => true}) if command.is_a?(Array) command = command.flatten.collect { |i| i.to_s } str = command.join(" ") @@ -301,9 +301,13 @@ module Util # The idea here is to avoid IO#read whenever possible. output_file="/dev/null" + error_file="/dev/null" if ! arguments[:squelch] require "tempfile" output_file = Tempfile.new("puppet") + if arguments[:combine] + error_file=output_file + end end oldverb = $VERBOSE @@ -319,7 +323,8 @@ module Util begin $stdin.reopen("/dev/null") $stdout.reopen(output_file) - $stderr.reopen(output_file) + $stderr.reopen(error_file) + 3.upto(256){|fd| IO::new(fd).close rescue nil} if arguments[:gid] Process.egid = arguments[:gid] -- cgit