Class: Webgen::Tag::ExecuteCommand

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/webgen/tag/executecommand.rb

Overview

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

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from Base

#create_tag_params, #param, #set_params

Methods included from WebsiteAccess

included, website

Methods included from Loggable

#log, #puts

Instance Method Details

#call(tag, body, context) ⇒ Object

Execute the command and return the standard output.



18
19
20
21
22
23
24
25
26
# File 'lib/webgen/tag/executecommand.rb', line 18

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