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
Timeout.timeout(args[:timeout]) do
status = popen4(command, args, &exec_processing_block)
end
rescue Timeout::Error => e
Chef::Log.error("#{command} exceeded timeout #{args[:timeout]}")
raise(e)
end
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