All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.install.products.ExecuteCommand
java.lang.Object
|
+----com.sun.install.products.ExecuteCommand
- public class ExecuteCommand
- extends Object
ExecuteCommand is a class that can represent a running command and return
its output and return values in a consistent fashion. It should be
used anytime you would normally use a java.lang.System.exec() call.
-
ERRORS
- Indicates we should collect the error output of the command (stderr in unix)
-
NORMAL
- Indicates we should collect the normal output of the command (stdout in unix)
-
ExecuteCommand(String)
- Create a command.
-
ExecuteCommand(String, InputStream)
- Create a command and indicate if it should collect output.
-
ExecuteCommand(String, InputStream, String[], int)
- Create a command and indicates which files (on the local filesystem)
the output of the command should be appended to, and what types to collect.
-
execute()
- Actually run the command and collect output if desired.
-
getAllOutput()
- Gets both the output and the error output (stdout and stderr,
respectively, on unix) from the command.
-
getCollectOutput()
-
-
getCommand()
-
-
getErrorMessage()
- Get the error message, if any
-
getErrors()
- Gets the error output (stderr on unix) from the command.
-
getOutput()
- Gets the output (stdout on unix) from the command.
-
getResult()
- Gets the exit result code from the command.
-
getState()
- Gets the state of the command.
-
getStdin()
-
-
readOutput(DataInputStream, DataInputStream)
- Reads the output and the error output from the command,
and stores it for later retrieval.
-
setCollectOutput(boolean)
-
-
setCommand(String)
-
-
setErrorMessage(String)
-
-
setLogFiles(String[])
-
-
setOutputType(int)
-
-
setResult(int)
-
-
setState(boolean)
- Sets the state of the command.
-
setStdin(InputStream)
-
NORMAL
public static final int NORMAL
- Indicates we should collect the normal output of the command (stdout in unix)
ERRORS
public static final int ERRORS
- Indicates we should collect the error output of the command (stderr in unix)
ExecuteCommand
public ExecuteCommand(String command)
- Create a command. The output is stored in memory until the command is finished. If
there is too much output, a java.lang.OutOfMemoryError will be thrown.
In that case, you should
setCollectOutput(false).
- Parameters:
- command - The command to execute
ExecuteCommand
public ExecuteCommand(String command,
InputStream stdin)
- Create a command and indicate if it should collect output. If you collect
output, the output is stored in memory until the command is finished. If
there is too much output, a java.lang.OutOfMemoryError will be thrown.
In that case, you should use the ExecuteCommand(String, int) variation
with a type of
NORMAL|ERRORS.
- Parameters:
- command - The command to execute
- collectOutput - Whether this ExecuteCommand should collect output.
ExecuteCommand
public ExecuteCommand(String command,
InputStream stdin,
String logOutputFiles[],
int which)
- Create a command and indicates which files (on the local filesystem)
the output of the command should be appended to, and what types to collect.
- Parameters:
- command - The command to execute
- logOutputFiles - The files to output the output of the command to.
setStdin
public void setStdin(InputStream stdin)
getStdin
public InputStream getStdin()
getCollectOutput
public boolean getCollectOutput()
setResult
public void setResult(int result)
setCollectOutput
public void setCollectOutput(boolean output)
setOutputType
public void setOutputType(int type)
setCommand
public void setCommand(String command)
getCommand
public String getCommand()
setLogFiles
public void setLogFiles(String logFiles[])
execute
public void execute()
- Actually run the command and collect output if desired.
getErrorMessage
public String getErrorMessage()
- Get the error message, if any
- Returns:
- The error message, if any from the command
getState
public boolean getState()
- Gets the state of the command. The state is false until the command
has started.
- Returns:
- The state of the command.
setState
public void setState(boolean state)
- Sets the state of the command. The state is false until the command
has started.
- Parameters:
- state - The state of the command.
getResult
public int getResult()
- Gets the exit result code from the command. On unix, normally
a non-zero result indicates something did not run correctly.
- Returns:
- The result code from the command, or -1 if the command has not run.
setErrorMessage
public void setErrorMessage(String errMsg)
getOutput
public String getOutput()
- Gets the output (stdout on unix) from the command.
- Returns:
- The output, if any, from the command.
getErrors
public String getErrors()
- Gets the error output (stderr on unix) from the command.
- Returns:
- The error output, if any, from the command.
getAllOutput
public String getAllOutput()
- Gets both the output and the error output (stdout and stderr,
respectively, on unix) from the command.
- Returns:
- A combination of output and error output, if any, from
the command
readOutput
protected void readOutput(DataInputStream in,
DataInputStream err)
- Reads the output and the error output from the command,
and stores it for later retrieval.
- Parameters:
- in - The stream representing the output from the program
- err - The stream representing the error output from the program.
All Packages Class Hierarchy This Package Previous Next Index