freemarker.ext.misc
Class Execute

java.lang.Object
  extended by freemarker.ext.misc.Execute
All Implemented Interfaces:
TemplateMethodModel, TemplateModel, java.io.Serializable

public final class Execute
extends java.lang.Object
implements TemplateMethodModel, java.io.Serializable

Gives FM-Classic the the ability to execute external commands. Will fork a process, and inline anything that process sends to stdout in the template. Based on a patch submitted by Peter Molettiere.

BE CAREFUL! this tag, depending on use, may allow you to set something up so that users of your web application could run arbitrary code on your server. This can only happen if you allow unchecked GET/POST submissions to be used as the command string in the exec method.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "exec", freemarker.ext.misc.Execute.getInstance() );

 ...
 

From your FM-Classic template:

 The following is executed:
 ${exec( "/usr/bin/ls" )}

 ...
 

Note:
Execute is a singleton instance. Use the getInstance() method to retrieve instances of this model.

Version:
$Id: Execute.java 1152 2013-04-15 10:34:50Z run2000 $
See Also:
Serialized Form

Method Summary
 TemplateModel exec(java.util.List<java.lang.String> arguments)
          Executes a method call.
static Execute getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Execute getInstance()
Retrieve a singleton instance of this class. Since there is no state information held between calls, there is only a need for one instance.

Returns:
an instance of this Execute class

exec

public TemplateModel exec(java.util.List<java.lang.String> arguments)
                   throws TemplateModelException
Executes a method call.

Specified by:
exec in interface TemplateMethodModel
Parameters:
arguments - a List of String objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
false, to indicate the object is not empty
Throws:
TemplateModelException