From 50a1f019535f61f7ed7e09931d0d114e5e4fd538 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 13 Sep 2011 11:45:45 +0100 Subject: Provide ability to download zip file containing complete request. Closes #11 --- lib/alaveteli_external_command.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/alaveteli_external_command.rb (limited to 'lib/alaveteli_external_command.rb') diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb new file mode 100644 index 000000000..b967c89b5 --- /dev/null +++ b/lib/alaveteli_external_command.rb @@ -0,0 +1,33 @@ +require 'external_command' + +module AlaveteliExternalCommand + class << self + def run(program_name, *args) + # Run an external program, and return its output. + # Standard error is suppressed unless the program + # fails (i.e. returns a non-zero exit status). + opts = {} + if !args.empty? && args[-1].is_a?(Hash) + opts = args.pop + end + + xc = ExternalCommand.new(program_name, *args) + if opts.has_key? :append_to + xc.out = opts[:append_to] + end + xc.run() + if xc.status != 0 + # Error + $stderr.puts("Error from #{program_name} #{args.join(' ')}:") + $stderr.print(xc.err) + return nil + else + if opts.has_key? :append_to + opts[:append_to] << "\n\n" + else + return xc.out + end + end + end + end +end -- cgit v1.2.3