def initialize(command, options={})
@environment = {"LC_ALL" => "C"}
@command = command
@status = nil
@stdout = ""
@stderr = ""
@stdin = nil
@cwd = Dir.tmpdir
@timeout = nil
options.each do |opt, val|
case opt.to_s
when "stdout"
raise "stdout should support <<" unless val.respond_to?("<<")
@stdout = val
when "stderr"
raise "stderr should support <<" unless val.respond_to?("<<")
@stderr = val
when "stdin"
raise "stdin should be a String" unless val.is_a?(String)
@stdin = val
when "cwd"
raise "Directory #{val} does not exist" unless File.directory?(val)
@cwd = val
when "environment"
if val.nil?
@environment = {}
else
@environment.merge!(val.dup)
@environment = @environment.delete_if { |k,v| v.nil? }
end
when "timeout"
raise "timeout should be a positive integer or the symbol :on_thread_exit symbol" unless val.eql?(:on_thread_exit) || ( val.is_a?(Fixnum) && val>0 )
@timeout = val
end
end
end