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.


Variable Index

 o ERRORS
Indicates we should collect the error output of the command (stderr in unix)
 o NORMAL
Indicates we should collect the normal output of the command (stdout in unix)

Constructor Index

 o ExecuteCommand(String)
Create a command.
 o ExecuteCommand(String, InputStream)
Create a command and indicate if it should collect output.
 o 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.

Method Index

 o execute()
Actually run the command and collect output if desired.
 o getAllOutput()
Gets both the output and the error output (stdout and stderr, respectively, on unix) from the command.
 o getCollectOutput()
 o getCommand()
 o getErrorMessage()
Get the error message, if any
 o getErrors()
Gets the error output (stderr on unix) from the command.
 o getOutput()
Gets the output (stdout on unix) from the command.
 o getResult()
Gets the exit result code from the command.
 o getState()
Gets the state of the command.
 o getStdin()
 o readOutput(DataInputStream, DataInputStream)
Reads the output and the error output from the command, and stores it for later retrieval.
 o setCollectOutput(boolean)
 o setCommand(String)
 o setErrorMessage(String)
 o setLogFiles(String[])
 o setOutputType(int)
 o setResult(int)
 o setState(boolean)
Sets the state of the command.
 o setStdin(InputStream)

Variables

 o NORMAL
 public static final int NORMAL
Indicates we should collect the normal output of the command (stdout in unix)

 o ERRORS
 public static final int ERRORS
Indicates we should collect the error output of the command (stderr in unix)

Constructors

 o 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
 o 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.
 o 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.

Methods

 o setStdin
 public void setStdin(InputStream stdin)
 o getStdin
 public InputStream getStdin()
 o getCollectOutput
 public boolean getCollectOutput()
 o setResult
 public void setResult(int result)
 o setCollectOutput
 public void setCollectOutput(boolean output)
 o setOutputType
 public void setOutputType(int type)
 o setCommand
 public void setCommand(String command)
 o getCommand
 public String getCommand()
 o setLogFiles
 public void setLogFiles(String logFiles[])
 o execute
 public void execute()
Actually run the command and collect output if desired.

 o getErrorMessage
 public String getErrorMessage()
Get the error message, if any

Returns:
The error message, if any from the command
 o 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.
 o 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.
 o 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.
 o setErrorMessage
 public void setErrorMessage(String errMsg)
 o getOutput
 public String getOutput()
Gets the output (stdout on unix) from the command.

Returns:
The output, if any, from the command.
 o getErrors
 public String getErrors()
Gets the error output (stderr on unix) from the command.

Returns:
The error output, if any, from the command.
 o 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
 o 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