summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlexander Tsvyashchenko <ndl@ndl.kiev.ua>2010-03-26 23:22:42 (GMT)
committerAlexander Tsvyashchenko <ndl@ndl.kiev.ua>2010-03-26 23:22:42 (GMT)
commit19440f038fdcb115d5decd3c74c0bc5d96b7476d (patch)
tree8dcff2f35ad40313c4a2f48c15826932a6156de9 /app
parent9b83e900f814db18a46cadd8e97b7b1a13c07440 (diff)
downloadwiki_external_filter-19440f038fdcb115d5decd3c74c0bc5d96b7476d.zip
wiki_external_filter-19440f038fdcb115d5decd3c74c0bc5d96b7476d.tar.gz
wiki_external_filter-19440f038fdcb115d5decd3c74c0bc5d96b7476d.tar.bz2
- More fixes to readme.
- Made popen4 optional.
Diffstat (limited to 'app')
-rw-r--r--app/helpers/wiki_external_filter_helper.rb29
1 files changed, 21 insertions, 8 deletions
diff --git a/app/helpers/wiki_external_filter_helper.rb b/app/helpers/wiki_external_filter_helper.rb
index d65bf41..db720b1 100644
--- a/app/helpers/wiki_external_filter_helper.rb
+++ b/app/helpers/wiki_external_filter_helper.rb
@@ -1,5 +1,4 @@
require 'digest/sha2'
-require 'open4'
module WikiExternalFilterHelper
@@ -86,13 +85,27 @@ module WikiExternalFilterHelper
c = nil
e = nil
- Open4::popen4(out['command']) { |pid, fin, fout, ferr|
- fin.write out['prolog'] if out.key?('prolog')
- fin.write CGI.unescapeHTML(text)
- fin.write out['epilog'] if out.key?('epilog')
- fin.close
- c, e = [fout.read, ferr.read]
- }
+ # If popen4 is available - use it as it provides stderr
+ # redirection so we can get more info in the case of error.
+ begin
+ require 'open4'
+
+ Open4::popen4(out['command']) { |pid, fin, fout, ferr|
+ fin.write out['prolog'] if out.key?('prolog')
+ fin.write CGI.unescapeHTML(text)
+ fin.write out['epilog'] if out.key?('epilog')
+ fin.close
+ c, e = [fout.read, ferr.read]
+ }
+ rescue LoadError
+ IO.popen(out['command'], 'r+b') { |f|
+ f.write out['prolog'] if out.key?('prolog')
+ f.write CGI.unescapeHTML(text)
+ f.write out['epilog'] if out.key?('epilog')
+ f.close_write
+ c = f.read
+ }
+ end
RAILS_DEFAULT_LOGGER.debug("child status: sig=#{$?.termsig}, exit=#{$?.exitstatus}")