aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-11-13 14:57:32 +0000
committerLouise Crow <louise.crow@gmail.com>2012-12-04 12:47:44 +0000
commit136c41f5e4c4510907e753a8b206ca688cbd9930 (patch)
tree9021e86335d2c8cbf4988c86123ab3417a413781 /lib
parent9af56ac5901790fb265a6492531eecbe5dd32f73 (diff)
Add some comments documenting the option params for the run method, pass in the binary_output flag if set.
Diffstat (limited to 'lib')
-rw-r--r--lib/alaveteli_external_command.rb14
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(' ')}:")