Package org.oddjob.jobs
Class ExecJob
- All Implemented Interfaces:
Serializable,Runnable,ArooaContextAware,ArooaSessionAware,Forceable,PropertyChangeNotifier,Iconic,ConsoleOwner,LogEnabled,Resettable,Stateful,Stoppable
- 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>
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the command.protected String[]voidAdd an argument.voidsetCommand(String command) Set the command to run.Methods inherited from class org.oddjob.jobs.ExecBase
commandTokenizer, consoleLog, execute, getDir, getEnvironment, getExitValue, getStderr, getStdin, getStdout, isNewEnvironment, isRedirectStderr, isStopForcibly, onStop, setDir, setEnvironment, setNewEnvironment, setRedirectStderr, setStderr, setStdin, setStdout, setStopForciblyMethods inherited from class org.oddjob.framework.extend.SimpleJob
fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onReset, run, sleep, softReset, stateHandler, stopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toStringMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
-
Constructor Details
-
ExecJob
public ExecJob()
-
-
Method Details
-
setArgs
Add an argument.- Parameters:
args- The arguments.
-
setCommand
Set the command to run.- Parameters:
command- The command.
-
getCommand
Get the command.- Returns:
- The command.
-
provideArgs
- Specified by:
provideArgsin classExecBase- Throws:
Exception
-