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
arguments | top |
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
environmentVariables | top |
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 instancePATH
.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 formatNAME=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:- See also:
- command
failOnErrors | top |
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)
inheritEnvironmentVariables | top |
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
logFooter | top |
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
logHeader | top |
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
permittedExtensions | top |
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
reportLevel | top |
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 levelparameters:l
– The new report level.
stderrStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stderr
.
- Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:s
– Thestderr
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.SEVERE
- See also:
- stdoutStrategy
stdoutStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stdout
.
- Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:s
– Thestdout
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.INFO
- See also:
- stderrStrategy
traceLogging | top |
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?
workingDirectory | top |
The working directory for the program. (The directory that the program is started in.)
- Setter method:
setWorkingDirectory(Object o)
parameters:- 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.
* 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.