[Index]

exec


Execute an external program. This job will flag complete if the return state of the external program is 0, otherwise it will flag 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.


Property Summary

args A string list of arguments.
command The command to execute.
dir The working directory.
environment An environment variable to be set before the program is executed.
exitValue The exit value of the process.
name A name, can be any text.
newEnvironment Create a fresh/clean environment.
redirectStderr Redirect the standard error stream in standard output.
stderr An output to where stderr of the proces will be written.
stdin An input stream which will act as stdin for the process.
stdout An output to where stdout for the process will be written.
stop This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.
stopForcibly Forcibly stop the process on stop.

Example Summary

Example 1 A simple example.
Example 2 Using the existing environment with an additional environment variable.
Example 3 Capturing console output to a file.
Example 4 Capturing console output to the logger.
Example 5 Using the output of one process as the input of another.

Property Detail

args

Configured ByELEMENT
AccessWRITE_ONLY
RequiredNo.

A string list of arguments.

command

Configured ByTEXT
AccessREAD_WRITE
Requiredyes, unless args are provided instead.

The command to execute. The command is interpreted as space delimited text which may be specified over several lines. Arguments that need to include spaces must be quoted. Within quoted arguments quotes may be escaped using a backslash.

dir

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo

The working directory.

environment

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

An environment variable to be set before the program is executed. This is a map like property.

exitValue

AccessREAD_ONLY

The exit value of the process.

name

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A name, can be any text.

newEnvironment

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

Create a fresh/clean environment.

redirectStderr

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

Redirect the standard error stream in standard output.

stderr

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

An output to where stderr of the proces will be written.

stdin

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

An input stream which will act as stdin for the process.

stdout

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

An output to where stdout for the process will be written.

stop

AccessREAD_ONLY
RequiredRead Only.

This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.

stopForcibly

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo, defaults to false.

Forcibly stop the process on stop.


Examples

Example 1

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>

Example 2

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>

Example 3

Capturing console output to a file. The output is Oddjob's command line help.

<oddjob id="this">
    <job>
        <exec id="exec" redirectStderr="true">
            <stdout>
                <file file="${work.dir}/ExecOutput.log"/>
            </stdout>
            java -jar "${oddjob.test.run.jar}" -h
        </exec>
    </job>
</oddjob>

Example 4

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>

Example 5

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>


(c) R Gordon Ltd 2005 - Present