com.sibvisions.util
Class Execute

java.lang.Object
  extended by com.sibvisions.util.Execute

public class Execute
extends java.lang.Object

The Execute class executes external programs.


Constructor Summary
Execute()
           
 
Method Summary
 void addEnvironmentParameter(java.lang.String pName, java.lang.String pValue)
          Adds an environment parameter.
 void addListener(IExecuteListener pListener)
          Adds an execution listener.
 void addParameter(java.lang.String pParam)
          Adds a launch parameter.
 void destroy()
          Destroyes the current process.
 void disableSend()
          Disables send feature.
 boolean execute(boolean pWait)
          Launches the given command in a new process.
 int getBufferCharacterCount()
          Gets the output buffer character count (default: 4000).
 java.lang.String getError()
          Gets the data of error stream from last exection.
 java.io.PrintStream getErrorForwarder()
          Gets the forwarder for error messages.
 java.lang.String getOutput()
          Gets the data of output stream from last exection.
 java.io.PrintStream getOutputForwarder()
          Gets the forwarder for standard output.
 java.lang.String getProgram()
          Gets the program to launch.
 java.io.File getWorkingDirectory()
          Gets the working directory, if set.
 boolean isParamsLogEnabled()
          Gets whether parameter logging is enabled.
 boolean isRunning()
          Gets whether the program is still running.
 boolean isUseSystemEnvironmentParameter()
          Gets whether the default environment parameters should be used.
 void removeListener(IExecuteListener pListener)
          Removes an execution listener.
 void send(byte[] pData)
          Sends the given data to the executed program.
 void setBufferCharacterCount(int pCharCount)
          Sets the output buffer character count.
 void setErrorForwarder(java.io.PrintStream pError)
          Sets the forwarder for error messages.
 void setOutputForwarder(java.io.PrintStream pOutput)
          Sets the forwarder for standard output.
 void setParamsLogEnabled(boolean pLog)
          Sets that parameter logging should be en- or disabled.
 void setProgram(java.lang.String pProgram)
          Sets the program to launch.
 void setUseSystemEnvironmentParameter(boolean pUseSystemEnv)
          Sets whether the default environment parameters should be used.
 void setWorkingDirectory(java.io.File pWorkDir)
          Sets the working directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Execute

public Execute()
Method Detail

setProgram

public void setProgram(java.lang.String pProgram)
Sets the program to launch.

Parameters:
pProgram - program path

getProgram

public java.lang.String getProgram()
Gets the program to launch.

Returns:
program path

addParameter

public void addParameter(java.lang.String pParam)
Adds a launch parameter.

Parameters:
pParam - parameter

addEnvironmentParameter

public void addEnvironmentParameter(java.lang.String pName,
                                    java.lang.String pValue)
Adds an environment parameter.

Parameters:
pName - the parameter name
pValue - the value

setUseSystemEnvironmentParameter

public void setUseSystemEnvironmentParameter(boolean pUseSystemEnv)
Sets whether the default environment parameters should be used.

Parameters:
pUseSystemEnv - true to use default environment parameters, false to use custom parameters (if set)

isUseSystemEnvironmentParameter

public boolean isUseSystemEnvironmentParameter()
Gets whether the default environment parameters should be used.

Returns:
true if default environment parameters will be merged with custom parameters (if set), false if only custom parameters will be used (if set).

execute

public boolean execute(boolean pWait)
                throws java.lang.Exception
Launches the given command in a new process.

Parameters:
pWait - true to wait until process is finished, false to continue
Returns:
if waiting is enabled, returns true if the exit code is 0. If waiting is disabled, returns true if the process was started.
Throws:
java.lang.Exception - if it's not possible to launch the given command

destroy

public void destroy()
Destroyes the current process.


getError

public java.lang.String getError()
Gets the data of error stream from last exection.

Returns:
null if execute(boolean) method was not called, otherwise the data of the error stream

getOutput

public java.lang.String getOutput()
Gets the data of output stream from last exection.

Returns:
null if execute(boolean) method was not called, otherwise the data of the o stream

setWorkingDirectory

public void setWorkingDirectory(java.io.File pWorkDir)
Sets the working directory.

Parameters:
pWorkDir - the directory

getWorkingDirectory

public java.io.File getWorkingDirectory()
Gets the working directory, if set.

Returns:
the working directory or null if no directory is set

setOutputForwarder

public void setOutputForwarder(java.io.PrintStream pOutput)
Sets the forwarder for standard output.

Parameters:
pOutput - the stream

getOutputForwarder

public java.io.PrintStream getOutputForwarder()
Gets the forwarder for standard output.

Returns:
the stream or null if no stream is set

setErrorForwarder

public void setErrorForwarder(java.io.PrintStream pError)
Sets the forwarder for error messages.

Parameters:
pError - the stream

getErrorForwarder

public java.io.PrintStream getErrorForwarder()
Gets the forwarder for error messages.

Returns:
the stream or null if no stream is set

addListener

public void addListener(IExecuteListener pListener)
Adds an execution listener.

Parameters:
pListener - the listener

removeListener

public void removeListener(IExecuteListener pListener)
Removes an execution listener.

Parameters:
pListener - the listener

send

public void send(byte[] pData)
          throws java.io.IOException
Sends the given data to the executed program.

Parameters:
pData - the data
Throws:
java.io.IOException - if program is not executed or a transmission error occurs

isRunning

public boolean isRunning()
Gets whether the program is still running.

Returns:
true if the program is executed and still running, false otherwise

setParamsLogEnabled

public void setParamsLogEnabled(boolean pLog)
Sets that parameter logging should be en- or disabled. This is useful if logging is generally enabled, but you want to hide the parameters e.g. if the confidental data is included.

Parameters:
pLog - true to turn off logging, false to use logging

isParamsLogEnabled

public boolean isParamsLogEnabled()
Gets whether parameter logging is enabled.

Returns:
true if parameter logging is enabled, false if parameter logging is disabled

setBufferCharacterCount

public void setBufferCharacterCount(int pCharCount)
Sets the output buffer character count.

Parameters:
pCharCount - the number of characters or -1 for unlimited characters
See Also:
getBufferCharacterCount()

getBufferCharacterCount

public int getBufferCharacterCount()
Gets the output buffer character count (default: 4000).

Returns:
the number of characters or -1 for unlimited characters

disableSend

public void disableSend()
Disables send feature. This call will close the output stream of the process, if already executing.



Copyright © 2009 SIB Visions GmbH. All Rights Reserved.