public class ExecJob extends SerializableJob implements Stoppable, ConsoleOwner
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.
<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>
<oddjob> <job> <exec name="Example With Environment" id="exec"> <environment> <value key="ODDJOB_FILE" value="myfile.txt"/> </environment> ${platform.set.command} </exec> </job> </oddjob>
<oddjob id="this"> <job> <exec redirectStderr="true"> <stdout> <file file="${work.dir}/ExecOutput.log"/> </stdout> java -jar "${oddjob.run.jar}" -h </exec> </job> </oddjob>
<oddjob id="this"> <job> <exec> <stdout> <logout level="INFO"/> </stdout> <stderr> <logout level="WARN"/> </stderr> java -jar ${oddjob.run.jar} -f Missing.xml </exec> </job> </oddjob>
<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.run.jar}" -f "${this.dir}/OddjobCat.xml" </exec> <exec id="exec"> <stdin> <value value="${vars.ourBuffer}"/> </stdin> <stdout> <stdout/> </stdout> java -jar "${oddjob.run.jar}" -f "${this.dir}/OddjobCat.xml" </exec> </jobs> </sequential> </job> </oddjob>
Constructor and Description |
---|
ExecJob() |
Modifier and Type | Method and Description |
---|---|
ArooaTokenizer |
commandTokenizer()
Provide the
ArooaTokenizer to use for parsing commands. |
LogArchive |
consoleLog()
Provide the console archive.
|
protected int |
execute()
Execute this job.
|
String |
getCommand()
Get the command.
|
File |
getDir() |
String |
getEnvironment(String name) |
int |
getExitValue() |
OutputStream |
getStderr()
Get the output stream for stderr.
|
InputStream |
getStdin()
Get the input stream for stdin.
|
OutputStream |
getStdout()
Get the output stream for stdout.
|
boolean |
isNewEnvironment() |
boolean |
isRedirectStderr() |
void |
onStop()
Allow sub classes to do something on stop.
|
void |
setArgs(String[] args)
Add an argument.
|
void |
setCommand(String command)
Set the command to run.
|
void |
setDir(File dir)
Set the working directory.
|
void |
setEnvironment(String name,
String value)
Add an environment variable.
|
void |
setNewEnvironment(boolean explicitEnvironment) |
void |
setRedirectStderr(boolean redirectErrorStream) |
void |
setStderr(OutputStream stderr)
Set the output stream stderr from the process will
be directed to.
|
void |
setStdin(InputStream stdin)
Set the input stream stdin for the process will
be read from.
|
void |
setStdout(OutputStream stdout)
Set the output stream stdout from the process will
be directed to.
|
fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onReset, run, sleep, softReset, stateHandler, stop
configure, getName, logger, logger, loggerName, save, setName, toString
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addStateListener, lastStateEvent, removeStateListener
public void setArgs(String[] args)
arg
- The argument.public void setCommand(String command)
command
- The command.public String getCommand()
public void setDir(File dir)
dir
- The working directory.public void setNewEnvironment(boolean explicitEnvironment)
Property: newEnvironment
Description: Create a fresh/clean environment.
Required: No.
public boolean isNewEnvironment()
public void setEnvironment(String name, String value)
nvp
- The name/value pair variable.public void setRedirectStderr(boolean redirectErrorStream)
Property: redirectStderr
Description: Redirect the standard error stream in standard output.
Required: No.
public boolean isRedirectStderr()
public void setStdin(InputStream stdin)
stdin
- An InputStream.public InputStream getStdin()
public void setStdout(OutputStream stdout)
stdout
- The output stream.public OutputStream getStdout()
public void setStderr(OutputStream stderr)
stderr
- The error stream.public OutputStream getStderr()
public ArooaTokenizer commandTokenizer()
ArooaTokenizer
to use for parsing commands.protected int execute() throws Exception
SimpleJob
public void onStop()
SimpleJob
public File getDir()
public int getExitValue()
public LogArchive consoleLog()
ConsoleOwner
consoleLog
in interface ConsoleOwner