Sha256: 054eebac6d96c2842e161ab2e1ece3b5d2833bde1f7a1d7783dad3862f5db5c8

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 Bytes

Contents

require 'cgi'
require 'tempfile'
require 'rbconfig'

module Webgen::Tag

  # Executes the given command and returns the standard output. All special HTML characters are
  # escaped.
  class ExecuteCommand

    include Webgen::Tag::Base

    BIT_BUCKET = (Config::CONFIG['arch'].include?('mswin32') ?  "nul" : "/dev/null")

    # Execute the command and return the standard output.
    def call(tag, body, context)
      command = param('tag.executecommand.command')
      output = `#{command} 2> #{BIT_BUCKET}`
      if ($? >> 8) != 0
        raise "Command '#{command}' in <#{context.ref_node.absolute_lcn}> has return value != 0: #{output}"
      end
      output = CGI::escapeHTML(output) if param('tag.executecommand.escape_html')
      [output, param('tag.executecommand.process_output')]
    end

  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.5.20081010 lib/webgen/tag/executecommand.rb
gettalong-webgen-0.5.5.20081012 lib/webgen/tag/executecommand.rb
gettalong-webgen-0.5.6.20081020 lib/webgen/tag/executecommand.rb
webgen-0.5.6 lib/webgen/tag/executecommand.rb