diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-01-15 16:05:25 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-01-15 16:05:25 +0000 |
commit | d1cac849b5c74e4f0d35b193ad24eed1d6b66af6 (patch) | |
tree | cb153b82b3e1d451be2d299b6114c99b6610b173 /lib/alaveteli_external_command.rb | |
parent | f25df72186683e54dd10fd5aa94e1e26dff8ea92 (diff) | |
parent | 7cc8cae3a669fc5de91d6bc23812c265e8af4c93 (diff) |
Merge branch 'release/0.6.9'
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(' ')}:") |