public class UnixExec extends java.lang.Object implements IExecute
Usage:
UnixExec exec = new UnixExec().command("git"); String[] options = {"rev-parse", "--abbrev-ref", "HEAD"}; exec.options(options); exec.output("stdout.log").mergeErrors(true); int rc = exec.execute();
Constructor and Description |
---|
UnixExec()
Default Constructor
|
Modifier and Type | Method and Description |
---|---|
UnixExec |
addOutput(java.lang.String rootDir,
java.lang.String file,
java.lang.String deployType)
Add an output file.
|
UnixExec |
command(java.lang.String command)
Sets the operating system command to be executed.
|
UnixExec |
error(java.lang.String file)
Redirects the stderr for the process to a file.
|
UnixExec |
errorEncoding(java.lang.String errorEncoding)
Sets the file encoding of the error file to be generated.
|
int |
execute()
Executes the UnixExec command.
|
int |
execute(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Executes the UnixExec command.
|
UnixExec |
file(java.lang.String file)
Set a file as the source file for this command.
|
java.util.Map<java.lang.String,java.lang.String> |
getEnvironment()
Gets a map of the current execution environment for the process.
|
java.lang.String |
getError()
Gets the error file.
|
java.lang.String |
getErrorEncoding()
Gets the file encoding of the error file to be generated.
|
java.lang.String |
getFile()
Returns the source file for this command execution.
|
java.lang.String |
getInput()
Gets the input file.
|
java.lang.String |
getOutput()
Gets the output file.
|
java.lang.String |
getOutputEncoding()
Gets the file encoding of the output file to be generated.
|
java.lang.String |
getWorkingDirectory()
Gets the working directory.
|
UnixExec |
input(java.lang.String file)
Redirects the stdin for the process to a file.
|
boolean |
isMergeErrors()
Whether error stream should be redirected to output stream.
|
UnixExec |
mergeErrors(boolean merge)
Sets whether stderr should be redirected to stdout.
|
UnixExec |
options(java.util.List<java.lang.String> options)
Sets the arguments to be passed to the command.
|
UnixExec |
output(java.lang.String file)
Redirects the stdout for the process to a file.
|
UnixExec |
outputEncoding(java.lang.String outputEncoding)
Sets the file encoding of the output file to be generated.
|
void |
setCommand(java.lang.String command)
Sets the operating system command to be executed.
|
void |
setError(java.lang.String file)
Redirects the stderr for the process to a file.
|
void |
setErrorEncoding(java.lang.String errorEncoding)
Sets the file encoding of the error file to be generated.
|
void |
setFile(java.lang.String file)
Set a file as the source file for this command.
|
void |
setInput(java.lang.String file)
Redirects the stdin for the process to a file.
|
void |
setMergeErrors(boolean merge)
Sets whether stderr should be redirected to stdout.
|
void |
setOptions(java.util.List<java.lang.String> options)
Sets the arguments to be passed to the command.
|
void |
setOutput(java.lang.String file)
Redirects the stdout for the process to a file.
|
void |
setOutputEncoding(java.lang.String outputEncoding)
Sets the file encoding of the output file to be generated.
|
void |
setTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Sets the timeout and time unit.
|
void |
setWorkingDirectory(java.lang.String directory)
Sets the working directory for the executing process.
|
UnixExec |
timeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Sets the timeout and time unit.
|
UnixExec |
workingDirectory(java.lang.String directory)
Sets the working directory for the executing process.
|
public final int execute() throws BuildException
execute
in interface IExecute
BuildException
- If an error occurred when executing the command.java.io.IOException
public final int execute(long timeout, java.util.concurrent.TimeUnit timeUnit) throws BuildException
timeout
- The amount of time to wait for process completion.timeUnit
- The duration unit for the timeout.BuildException
- If an error occurred when executing the command or if
the timeout expires before command completion.java.io.IOException
public void setTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit)
timeout
- The amount of time to wait for process completion.timeUnit
- The duration unit for the timeout.public UnixExec timeout(long timeout, java.util.concurrent.TimeUnit timeUnit)
timeout
- The amount of time to wait for process completion.timeUnit
- The duration unit for the timeout.public UnixExec command(java.lang.String command)
command
- the program to be executedpublic void setCommand(java.lang.String command)
command
- the program to be executedpublic UnixExec options(java.util.List<java.lang.String> options)
options
- The list of optionspublic void setOptions(java.util.List<java.lang.String> options)
options
- The list of optionspublic java.lang.String getOutputEncoding()
public void setOutputEncoding(java.lang.String outputEncoding)
outputEncoding
- The output encoding.public UnixExec outputEncoding(java.lang.String outputEncoding)
outputEncoding
- The output encoding.public java.lang.String getErrorEncoding()
public void setErrorEncoding(java.lang.String errorEncoding)
errorEncoding
- The error encoding.public UnixExec errorEncoding(java.lang.String errorEncoding)
errorEncoding
- The error encoding.public UnixExec addOutput(java.lang.String rootDir, java.lang.String file, java.lang.String deployType)
rootDir
- The root directory of the file, or null if file is an absolute file path.file
- Absolute or local path to a file that should be recorded as outputdeployType
- the deploy type for this output filepublic UnixExec workingDirectory(java.lang.String directory)
directory
- the path of the working directorypublic void setWorkingDirectory(java.lang.String directory)
directory
- the path of the working directorypublic java.lang.String getWorkingDirectory()
public java.util.Map<java.lang.String,java.lang.String> getEnvironment()
public void setInput(java.lang.String file)
file
- path to the input filepublic UnixExec input(java.lang.String file)
file
- path to the input filepublic java.lang.String getInput()
public void setOutput(java.lang.String file)
file
- path to the output filepublic UnixExec output(java.lang.String file)
file
- path to the output filepublic java.lang.String getOutput()
public void setError(java.lang.String file)
file
- path to the error filepublic UnixExec error(java.lang.String file)
file
- path to the error filepublic java.lang.String getError()
public void setFile(java.lang.String file)
file
- the path to the source filepublic UnixExec file(java.lang.String file)
file
- the path to the source filepublic java.lang.String getFile()
public void setMergeErrors(boolean merge)
merge
- true if stderr should be redirectedpublic UnixExec mergeErrors(boolean merge)
merge
- true if stderr should be redirectedpublic boolean isMergeErrors()
<IBM Copyright © 2018 IBM Corp. All Rights Reserved.