Package com.ibm.di.function
Class ExecuteCommand
- java.lang.Object
-
- com.ibm.di.function.ExecuteCommand
-
public class ExecuteCommand extends java.lang.Object
This class is a helper class used to execute operating system commands. This class is used by the UserFunctions class, which provides helper functions through scripting to TDI users.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExecuteCommand.StreamReader
Local thread that reads an input stream and buffers the stream in a string buffer.
-
Constructor Summary
Constructors Constructor Description ExecuteCommand()
Constructor for the ExecuteCommand object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
exec(java.lang.Process p)
This method starts two background threads that read the input and error streams of the Process object.int
exec(java.lang.String command)
Execute command and wait for termination.int
exec(java.lang.String[] cmdargs)
Execute command and wait for termination.boolean
failed()
Returns true if there was an error executing the last processjava.lang.Exception
getError()
Returns the error object from the last execution.java.lang.String
getErrorBuffer()
Returns the standard error from the process as a string.int
getExitValue()
Returns the exit code for the last completed process.java.lang.String
getOutputBuffer()
Returns the standard output from the process as a string.java.lang.Process
getProcess()
Returns the Process object of the current/last active process.void
setEncoding(java.lang.String cp)
-
-
-
Method Detail
-
exec
public int exec(java.lang.String command)
Execute command and wait for termination.- Parameters:
command
- The command to execute- Returns:
- The exit code
-
exec
public int exec(java.lang.String[] cmdargs)
Execute command and wait for termination.- Parameters:
cmdargs
- The command (first item) and its arguments- Returns:
- The exit code
-
exec
public int exec(java.lang.Process p)
This method starts two background threads that read the input and error streams of the Process object. The returned value is the exit code of the process (this method waits for the process to complete).- Parameters:
p
- The executing process- Returns:
- The exit code
-
getProcess
public java.lang.Process getProcess()
Returns the Process object of the current/last active process.- Returns:
- The process value
-
getExitValue
public int getExitValue()
Returns the exit code for the last completed process.- Returns:
- The exitValue value. A value of -1 means that the process failed with an Exception.
-
failed
public boolean failed()
Returns true if there was an error executing the last process- Returns:
- a boolean value - true if there was an error executing the last process, false otherwise
-
getOutputBuffer
public java.lang.String getOutputBuffer()
Returns the standard output from the process as a string.- Returns:
- The outputBuffer value
-
getErrorBuffer
public java.lang.String getErrorBuffer()
Returns the standard error from the process as a string.- Returns:
- The errorBuffer value
-
getError
public java.lang.Exception getError()
Returns the error object from the last execution.- Returns:
- The error value
-
setEncoding
public void setEncoding(java.lang.String cp)
-
-