Class ExecJob

All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, ConsoleOwner, LogEnabled, Resettable, Stateful, Stoppable

public class ExecJob extends ExecBase
Author:
Rob Gordon.
See Also:

Description

Execute an external program. This job will wait for the process to terminate and be COMPLETE if the return state of the external program is 0, otherwise it will be NOT COMPLETE.

Processes may behave differently on different operating systems - for instance stop doesn't always kill the process. Please see http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4109888 for additional information.

Example

A simple example.
<exec name="Batch Example">

cmd /C "${oddjob.dir}\bin\greeting.bat" Hello

</exec>
Oddjob will treat arguments in quotes as single program argument and allows them to be escaped with backslash. If this is too confusing it is sometimes easier to specify the command as individual arguments. The above is equivalent to:
<exec name="Batch Example">

    <args>

        <list>

            <values>

                <value value="cmd"/>

                <value value="/C"/>

                <value value="${oddjob.dir}\bin\greeting.bat"/>

                <value value="Hello"/>

            </values>

        </list>

    </args>

</exec>
Using the existing environment with an additional environment variable.
<oddjob>

    <job>

        <exec name="Example With Environment" id="exec">

            <environment>

                <value key="ODDJOB_FILE" value="myfile.txt"/>

            </environment>

${platform.set.command}

        </exec>

    </job>

</oddjob>
Capturing console output to a file. The output is Oddjob's command line help.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <properties/>

                <exec id="exec" redirectStderr="true">

                    <stdout>

                        <file file="${work.dir}/ExecOutput.log"/>

                    </stdout>

                    java -jar "${oddjob.test.run.jar}" -h

                </exec>

            </jobs>

        </sequential>

    </job>

</oddjob>
Capturing console output to the logger. Note how the logger output can be defined with different log levels for stdout and sterr.
<oddjob id="this">

    <job>

        <exec>

            <stdout>

                <logout level="INFO"/>

            </stdout>

            <stderr>

                <logout level="WARN"/>

            </stderr>

            java -jar ${oddjob.test.run.jar} -f Missing.xml ${logConfigArgs}/

        </exec>

    </job>

</oddjob>
Using the output of one process as the input of another. Standard input for the first process is provided by a buffer. A second buffer captures the output of that process and passess it to the second process. The output of the second process is captured and sent to the console of the parent process.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <variables id="vars">

                    <ourBuffer>

                        <buffer/>

                    </ourBuffer>

                </variables>

                <exec>

                    <stdin>

                        <buffer>apples

oranges

pears

</buffer>

                    </stdin>

                    <stdout>

                        <value value="${vars.ourBuffer}"/>

                    </stdout>

java -jar "${oddjob.test.run.jar}" -f "${this.dir}/OddjobCat.xml" ${logConfigArgs}

        </exec>

                <exec id="exec">

                    <stdin>

                        <value value="${vars.ourBuffer}"/>

                    </stdin>

                    <stdout>

                        <stdout/>

                    </stdout>

java -jar "${oddjob.test.run.jar}" -f "${this.dir}/OddjobCat.xml" ${logConfigArgs}

        </exec>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Constructor Details

    • ExecJob

      public ExecJob()
  • Method Details

    • setArgs

      public void setArgs(String[] args)
      Add an argument.
      Parameters:
      args - The arguments.
    • setCommand

      public void setCommand(String command)
      Set the command to run.
      Parameters:
      command - The command.
    • getCommand

      public String getCommand()
      Get the command.
      Returns:
      The command.
    • provideArgs

      protected String[] provideArgs() throws Exception
      Specified by:
      provideArgs in class ExecBase
      Throws:
      Exception