#!/usr/bin/ruby require "Tempfile" cmd = ARGV.join(' ') # Create a temp file that will be deleted when this script completes tempfile = Tempfile.new("temp") tempfile.close # So that child process can write to it # Execute the requested command, saving STDERR to our temp file, # capturing STDOUT and the exit code output = `#{cmd} 2> #{tempfile.path}` code = $? # Read temp file that may contain STDERR output tempfile.open err_text = tempfile.readlines.join if code == 0 puts "Command executed successfully." puts " " puts "--------------------------------------------------------------------------------" puts "Summary: " puts "--------------------------------------------------------------------------------" puts " " puts "Command: " + cmd puts " " puts "--------------------------------------------------------------------------------" puts "Details: " puts "--------------------------------------------------------------------------------" puts " " puts output else puts "Command failed." puts " " puts "--------------------------------------------------------------------------------" puts "Summary: " puts "--------------------------------------------------------------------------------" puts " " puts "Command: " + cmd puts "Exit code: " + code.to_s puts " " puts "--------------------------------------------------------------------------------" puts "Details: " puts "--------------------------------------------------------------------------------" puts " " puts err_text end # Exit the script with the same exit code we received exit code