diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index c7e08e27..c446e08a 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -5,10 +5,14 @@ require 'digest/md5' require 'rbconfig' -if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9') - require 'win32/open3' +if ENV['WICKED_POPEN'] == 'ruby' + if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9') + require 'win32/open3' + else + require 'open3' + end else - require 'open3' + require 'posix/spawn' end begin @@ -75,8 +79,13 @@ def pdf_from_url(url, options = {}) print_command(command.inspect) if in_development_mode? - err = Open3.popen3(*command) do |_stdin, _stdout, stderr| - stderr.read + err = if ENV['WICKED_POPEN'] == 'ruby' + Open3.popen3(*command) do |_stdin, _stdout, stderr| + stderr.read + end + else + child = POSIX::Spawn::Child.new(*command) + child.err end if options[:return_file] return_file = options.delete(:return_file) diff --git a/wicked_pdf.gemspec b/wicked_pdf.gemspec index ceddc25b..00572e90 100644 --- a/wicked_pdf.gemspec +++ b/wicked_pdf.gemspec @@ -27,6 +27,7 @@ DESC spec.requirements << 'wkhtmltopdf' spec.add_dependency 'activesupport' + spec.add_dependency 'posix-spawn', '~> 0.3.11' spec.add_development_dependency 'rails' spec.add_development_dependency 'bundler', '~> 1.3'