Package com.ibm.dbb.build
Class UnixExec
- java.lang.Object
-
- com.ibm.dbb.build.UnixExec
-
- All Implemented Interfaces:
IExecute
public class UnixExec extends java.lang.Object implements IExecute
The UnixExec class is used to execute a z/OS UNIX command.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 Summary
Constructors Constructor Description UnixExec()Default Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UnixExecaddOutput(java.lang.String rootDir, java.lang.String file, java.lang.String deployType)Add an output file.UnixExeccommand(java.lang.String command)Sets the operating system command to be executed.UnixExecerror(java.lang.String file)Redirects the stderr for the process to a file.UnixExecerrorEncoding(java.lang.String errorEncoding)Sets the file encoding of the error file to be generated.intexecute()Executes the UnixExec command.intexecute(long timeout, java.util.concurrent.TimeUnit timeUnit)Executes the UnixExec command.UnixExecfile(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.StringgetError()Gets the error file.java.lang.StringgetErrorEncoding()Gets the file encoding of the error file to be generated.java.lang.StringgetFile()Returns the source file for this command execution.java.lang.StringgetInput()Gets the input file.java.lang.StringgetOutput()Gets the output file.java.lang.StringgetOutputEncoding()Gets the file encoding of the output file to be generated.java.lang.StringgetWorkingDirectory()Gets the working directory.UnixExecinput(java.lang.String file)Redirects the stdin for the process to a file.booleanisMergeErrors()Whether error stream should be redirected to output stream.UnixExecmergeErrors(boolean merge)Sets whether stderr should be redirected to stdout.UnixExecoptions(java.util.List<java.lang.String> options)Sets the arguments to be passed to the command.UnixExecoutput(java.lang.String file)Redirects the stdout for the process to a file.UnixExecoutputEncoding(java.lang.String outputEncoding)Sets the file encoding of the output file to be generated.voidsetCommand(java.lang.String command)Sets the operating system command to be executed.voidsetError(java.lang.String file)Redirects the stderr for the process to a file.voidsetErrorEncoding(java.lang.String errorEncoding)Sets the file encoding of the error file to be generated.voidsetFile(java.lang.String file)Set a file as the source file for this command.voidsetInput(java.lang.String file)Redirects the stdin for the process to a file.voidsetMergeErrors(boolean merge)Sets whether stderr should be redirected to stdout.voidsetOptions(java.util.List<java.lang.String> options)Sets the arguments to be passed to the command.voidsetOutput(java.lang.String file)Redirects the stdout for the process to a file.voidsetOutputEncoding(java.lang.String outputEncoding)Sets the file encoding of the output file to be generated.voidsetTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit)Sets the timeout and time unit.voidsetWorkingDirectory(java.lang.String directory)Sets the working directory for the executing process.UnixExectimeout(long timeout, java.util.concurrent.TimeUnit timeUnit)Sets the timeout and time unit.UnixExecworkingDirectory(java.lang.String directory)Sets the working directory for the executing process.
-
-
-
Method Detail
-
execute
public final int execute() throws BuildExceptionExecutes the UnixExec command. This method waits for the process to complete with a default timeout of 1 hour.- Specified by:
executein interfaceIExecute- Returns:
- The integer RC from the executed command.
- Throws:
BuildException- If an error occurred when executing the command.java.io.IOException
-
execute
public final int execute(long timeout, java.util.concurrent.TimeUnit timeUnit) throws BuildExceptionExecutes the UnixExec command.- Parameters:
timeout- The amount of time to wait for process completion.timeUnit- The duration unit for the timeout.- Returns:
- The integer RC from the executed command.
- Throws:
BuildException- If an error occurred when executing the command or if the timeout expires before command completion.java.io.IOException
-
setTimeout
public void setTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit)Sets the timeout and time unit.- Parameters:
timeout- The amount of time to wait for process completion.timeUnit- The duration unit for the timeout.
-
timeout
public UnixExec timeout(long timeout, java.util.concurrent.TimeUnit timeUnit)
Sets the timeout and time unit.- Parameters:
timeout- The amount of time to wait for process completion.timeUnit- The duration unit for the timeout.- Returns:
- this UnixExec
-
command
public UnixExec command(java.lang.String command)
Sets the operating system command to be executed.- Parameters:
command- the program to be executed- Returns:
- this UnixExec
-
setCommand
public void setCommand(java.lang.String command)
Sets the operating system command to be executed.- Parameters:
command- the program to be executed
-
options
public UnixExec options(java.util.List<java.lang.String> options)
Sets the arguments to be passed to the command.- Parameters:
options- The list of options- Returns:
- this UnixExec
-
setOptions
public void setOptions(java.util.List<java.lang.String> options)
Sets the arguments to be passed to the command.- Parameters:
options- The list of options
-
getOutputEncoding
public java.lang.String getOutputEncoding()
Gets the file encoding of the output file to be generated.- Returns:
- The output encoding.
-
setOutputEncoding
public void setOutputEncoding(java.lang.String outputEncoding)
Sets the file encoding of the output file to be generated.- Parameters:
outputEncoding- The output encoding.
-
outputEncoding
public UnixExec outputEncoding(java.lang.String outputEncoding)
Sets the file encoding of the output file to be generated.- Parameters:
outputEncoding- The output encoding.- Returns:
- This UnixExec.
-
getErrorEncoding
public java.lang.String getErrorEncoding()
Gets the file encoding of the error file to be generated.- Returns:
- The error encoding.
-
setErrorEncoding
public void setErrorEncoding(java.lang.String errorEncoding)
Sets the file encoding of the error file to be generated.- Parameters:
errorEncoding- The error encoding.
-
errorEncoding
public UnixExec errorEncoding(java.lang.String errorEncoding)
Sets the file encoding of the error file to be generated.- Parameters:
errorEncoding- The error encoding.- Returns:
- This UnixExec
-
addOutput
public UnixExec addOutput(java.lang.String rootDir, java.lang.String file, java.lang.String deployType)
Add an output file.- Parameters:
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 file- Returns:
- this UnixExec
-
workingDirectory
public UnixExec workingDirectory(java.lang.String directory)
Sets the working directory for the executing process. Defaults to the directory named by the system property user.dir.- Parameters:
directory- the path of the working directory- Returns:
- this UnixExec
-
setWorkingDirectory
public void setWorkingDirectory(java.lang.String directory)
Sets the working directory for the executing process. Defaults to the directory named by the system property user.dir.- Parameters:
directory- the path of the working directory
-
getWorkingDirectory
public java.lang.String getWorkingDirectory()
Gets the working directory.- Returns:
- the working directory
-
getEnvironment
public java.util.Map<java.lang.String,java.lang.String> getEnvironment()
Gets a map of the current execution environment for the process. The initial environment is a copy of the current process environment. Clear the returned map to start with a fresh environment. Add or modify values in the returned map to change the environment.- Returns:
- a map of key/value pairs for the environment
-
setInput
public void setInput(java.lang.String file)
Redirects the stdin for the process to a file.- Parameters:
file- path to the input file
-
input
public UnixExec input(java.lang.String file)
Redirects the stdin for the process to a file.- Parameters:
file- path to the input file- Returns:
- this UnixExec
-
getInput
public java.lang.String getInput()
Gets the input file.- Returns:
- path to the input file
-
setOutput
public void setOutput(java.lang.String file)
Redirects the stdout for the process to a file.- Parameters:
file- path to the output file
-
output
public UnixExec output(java.lang.String file)
Redirects the stdout for the process to a file.- Parameters:
file- path to the output file- Returns:
- this UnixExec
-
getOutput
public java.lang.String getOutput()
Gets the output file.- Returns:
- path to the output file
-
setError
public void setError(java.lang.String file)
Redirects the stderr for the process to a file.- Parameters:
file- path to the error file
-
error
public UnixExec error(java.lang.String file)
Redirects the stderr for the process to a file.- Parameters:
file- path to the error file- Returns:
- this UnixExec
-
getError
public java.lang.String getError()
Gets the error file.- Returns:
- path to the error file
-
setFile
public void setFile(java.lang.String file)
Set a file as the source file for this command. This file is reported as the source in the resulting UnixRecord.- Parameters:
file- the path to the source file
-
file
public UnixExec file(java.lang.String file)
Set a file as the source file for this command. This file is reported as the source in the resulting UnixRecord.- Parameters:
file- the path to the source file
-
getFile
public java.lang.String getFile()
Returns the source file for this command execution.- Returns:
- the path to the source file
-
setMergeErrors
public void setMergeErrors(boolean merge)
Sets whether stderr should be redirected to stdout. Default is false.- Parameters:
merge- true if stderr should be redirected
-
mergeErrors
public UnixExec mergeErrors(boolean merge)
Sets whether stderr should be redirected to stdout. Default is false.- Parameters:
merge- true if stderr should be redirected- Returns:
- this UnixExec
-
isMergeErrors
public boolean isMergeErrors()
Whether error stream should be redirected to output stream. Default is false.- Returns:
- true if streams are merged
-
-