summaryrefslogtreecommitdiff
path: root/lib/chef/mixin/command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/mixin/command.rb')
-rw-r--r--lib/chef/mixin/command.rb28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/chef/mixin/command.rb b/lib/chef/mixin/command.rb
index 719151a6b6..2cc25e149e 100644
--- a/lib/chef/mixin/command.rb
+++ b/lib/chef/mixin/command.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,23 +41,23 @@ class Chef
# === Parameters
# args<Hash>: A number of required and optional arguments
- # command<String>, <Array>: A complete command with options to execute or a command and options as an Array
+ # command<String>, <Array>: A complete command with options to execute or a command and options as an Array
# creates<String>: The absolute path to a file that prevents the command from running if it exists
# cwd<String>: Working directory to execute command in, defaults to Dir.tmpdir
# timeout<String>: How many seconds to wait for the command to execute before timing out
# returns<String>: The single exit value command is expected to return, otherwise causes an exception
# ignore_failure<Boolean>: Whether to raise an exception on failure, or just return the status
# output_on_failure<Boolean>: Return output in raised exception regardless of Log.level
- #
+ #
# user<String>: The UID or user name of the user to execute the command as
# group<String>: The GID or group name of the group to execute the command as
# environment<Hash>: Pairs of environment variable names and their values to set before execution
#
# === Returns
# Returns the exit status of args[:command]
- def run_command(args={})
+ def run_command(args={})
status, stdout, stderr = run_command_and_return_stdout_stderr(args)
-
+
status
end
@@ -77,7 +77,7 @@ class Chef
return false
end
end
-
+
status, stdout, stderr = output_of_command(args[:command], args)
command_output << "STDOUT: #{stdout}"
command_output << "STDERR: #{stderr}"
@@ -89,16 +89,16 @@ class Chef
def output_of_command(command, args)
Chef::Log.debug("Executing #{command}")
stderr_string, stdout_string, status = "", "", nil
-
+
exec_processing_block = lambda do |pid, stdin, stdout, stderr|
stdout_string, stderr_string = stdout.string.chomp, stderr.string.chomp
end
-
+
args[:cwd] ||= Dir.tmpdir
unless ::File.directory?(args[:cwd])
raise Chef::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory"
end
-
+
Dir.chdir(args[:cwd]) do
if args[:timeout]
begin
@@ -112,17 +112,17 @@ class Chef
else
status = popen4(command, args, &exec_processing_block)
end
-
+
Chef::Log.debug("---- Begin output of #{command} ----")
Chef::Log.debug("STDOUT: #{stdout_string}")
Chef::Log.debug("STDERR: #{stderr_string}")
Chef::Log.debug("---- End output of #{command} ----")
Chef::Log.debug("Ran #{command} returned #{status.exitstatus}")
end
-
+
return status, stdout_string, stderr_string
end
-
+
def handle_command_failures(status, command_output, opts={})
unless opts[:ignore_failure]
opts[:returns] ||= 0
@@ -138,7 +138,7 @@ class Chef
end
end
end
-
+
# Call #run_command but set LC_ALL to the system's current environment so it doesn't get changed to C.
#
# === Parameters