diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-01-15 17:04:06 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-01-15 17:04:06 +1100 |
commit | e6c80e93df44a436d9c94a9c076eb321df249b2a (patch) | |
tree | f2396181cfadeca370446f936f0bc4c1da3888dd /lib/alaveteli_external_command.rb | |
parent | b5f2bed1e406cd7fb6b50259a57be201c797db7d (diff) | |
parent | 843805e5d92eded943bd2a32b02ac967539245e8 (diff) |
Merge remote-tracking branch 'mysociety/develop' into rails_xss
Diffstat (limited to 'lib/alaveteli_external_command.rb')
-rw-r--r-- | lib/alaveteli_external_command.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index 3bfc34e3a..24b4b1aa8 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -2,6 +2,12 @@ require 'external_command' module AlaveteliExternalCommand class << self + # Final argument can be a hash of options. + # Valid options are: + # :append_to - string to append the output of the process to + # :stdin_string - stdin string to pass to the process + # :binary_output - boolean flag for treating the output as binary or text (only significant + # ruby 1.9 and above) def run(program_name, *args) # Run an external program, and return its output. # Standard error is suppressed unless the program @@ -10,7 +16,7 @@ module AlaveteliExternalCommand if !args.empty? && args[-1].is_a?(Hash) opts = args.pop end - + if program_name =~ %r(^/) program_path = program_name else @@ -24,12 +30,16 @@ module AlaveteliExternalCommand end raise "Could not find #{program_name} in any of #{Configuration::utility_search_path.join(', ')}" if !found end - + xc = ExternalCommand.new(program_path, *args) if opts.has_key? :append_to xc.out = opts[:append_to] end + if opts.has_key? :binary_output + xc.binary_mode = opts[:binary_output] + end xc.run(opts[:stdin_string] || "", opts[:env] || {}) + if xc.status != 0 # Error $stderr.puts("Error from #{program_name} #{args.join(' ')}:") |