ExtProcessTF

Run an external program.

Task package:org.schmant.task.base
Java package:org.schmant.task.process
Category:Execution tasks
Since:0.5
EntityFS-aware?No*
See also:TimedExecutionTF

Description:

Run an external program (an executable or a command).

Required properties

Properties

argumentstop

Arguments to the program. The arguments will be given to the program in the order that they are added.

Setter method:
addArgument(String arg)
Add one program argument.
parameters:
arg – The program argument, for instance -f out.txt.
Setter method:
addArguments(Object o)
Add one program argument or an array or a collection of program arguments.
parameters:
o – One program argument or an array or collection of program arguments (strings).
Setter method:
clearArguments()
Clear the list of program arguments.
command (semi-required) top

The name of the command to run. The first matching command found in any of the directories listed in the PATH environment variable will be used. To have different permitted file name extensions for the command, set the permittedExtensions property.

Setter method:
setCommand(String s)
parameters:
s – The name of the command to run.
See also:
executable
permittedExtensions
environmentVariablestop

Environment variables for the program. By default, the variables set are added to the environment of the Schmant script. See the inheritEnvironmentVariables property.

Setter method:
addEnvironmentVariable(String name, String value)
parameters:
name – The environment variable name, for instance PATH.
value – The value of the variable.
Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.
parameters:
o – A string or an array or collection of strings. Each string must have the format NAME=VALUE.
Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.
See also:
inheritEnvironmentVariables
executable (semi-required) top

The exact path to the program to run.

Setter method:
setExecutable(Object o)
parameters:
o – The program executable.
Interpreted by InterpretAsFileStrategy.
See also:
command
failOnErrorstop

If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.

Setter method:
setFailOnErrors(boolean b)
parameters:
b – Should the task fail on errors?
Default value:
true (fails on errors)
inheritEnvironmentVariablestop

Should the environment variables of the Schmant script be inherited?

Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:
b – Should environment variables be inherited?
Default value:
true (environment variables are inherited)
See also:
environmentVariables
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(String s)
parameters:
s – The footer message.
Default value:
Empty (no footer message is logged.)
See also:
logHeader
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(String s)
parameters:
s – The header message.
Default value:
A task class specific message.
See also:
logFooter
permittedExtensionstop

A collection of permitted file name extensions for the command. This is used together with the command property. For instance, the command bash and the permitted extensions [empty String] and exe, would match the commands bash and bash.exe.

Setter method:
addPermittedExtension(String s)
Add one permitted file name extension for the command.
parameters:
s – The permitted file name extension (without a leading dot). Set an empty string to allow the command without any extension.
Setter method:
addPermittedExtensions(Object o)
Add one or several permitted file name extensions for the command.
parameters:
o – One permitted file name extension or an array or collection of permitted file name extensions (strings), without leading dots.
Setter method:
clearPermittedExtensions()
Clear the collection of permitted file name extensions.
See also:
command
reportLeveltop

This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.

Setter method:
setReportLevel(Level l)
Set the report level
parameters:
l – The new report level.
stderrStrategytop

A ProcessOutputStrategy for handling the program's output to stderr.

Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:
s – The stderr strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.SEVERE
See also:
stdoutStrategy
stdoutStrategytop

A ProcessOutputStrategy for handling the program's output to stdout.

Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:
s – The stdout strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.INFO
See also:
stderrStrategy
traceLoggingtop

If trace logging is enabled for a task, it reports its configuration before it is run.

Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).

Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.
parameters:
b – Enable trace logging?
workingDirectorytop

The working directory for the program. (The directory that the program is started in.)

Setter method:
setWorkingDirectory(Object o)
parameters:
o – A directory.
Interpreted by InterpretAsFileDirectoryStrategy.
Default value:
The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.

Examples

Example 1

Use the wget command to get the front page from www.dn.se. Give up if we don't get any answer in ten seconds.

// Use this strategy for collecting stdout output from the command sos = new SaveToStringProcessOutputStrategy(); // Run a timed execution new TimedExecutionTF(). setTime(10, TimeUnit.SECONDS). setTaskFactory( new ExtProcessTF(). setCommand("wget"). addPermittedExtension(""). addPermittedExtension("exe"). addArgument("http://www.dn.se"). setStdoutStrategy(sos)).run(); // Now, the string from sos.getOutput() can be read.


* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.