com.sibvisions.util
Class Execute

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

public class Execute
extends Object

The Execute class executes external programs.


Constructor Summary
Execute()
           
 
Method Summary
 void addListener(IExecuteListener pListener)
          Adds an execution listener.
 void addParameter(String pParam)
          Adds a launch parameter.
 void destroy()
          Destroyes the current process.
 boolean execute(boolean pWait)
          Launches the given command in a new process.
 int getBufferCharacterCount()
          Gets the output buffer character count (default: 4000).
 String getError()
          Gets the data of error stream from last exection.
 PrintStream getErrorForwarder()
          Gets the forwarder for error messages.
 String getOutput()
          Gets the data of output stream from last exection.
 PrintStream getOutputForwarder()
          Gets the forwarder for standard output.
 String getProgram()
          Gets the program to launch.
 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.
 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(PrintStream pError)
          Sets the forwarder for error messages.
 void setOutputForwarder(PrintStream pOutput)
          Sets the forwarder for standard output.
 void setParamsLogEnabled(boolean pLog)
          Sets that parameter logging should be en- or disabled.
 void setProgram(String pProgram)
          Sets the program to launch.
 void setWorkingDirectory(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(String pProgram)
Sets the program to launch.

Parameters:
pProgram - program path

getProgram

public String getProgram()
Gets the program to launch.

Returns:
program path

addParameter

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

Parameters:
pParam - parameter

execute

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

Parameters:
pWait - true to wait until process is finished, false to continue
Returns:
if the command was executed or execution is started (possible when wait is disabled)
Throws:
Exception - if it's not possible to launch the given command

destroy

public void destroy()
Destroyes the current process.


getError

public 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 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(File pWorkDir)
Sets the working directory.

Parameters:
pWorkDir - the directory

getWorkingDirectory

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

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

setOutputForwarder

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

Parameters:
pOutput - the stream

getOutputForwarder

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

Returns:
the stream or null if no stream is set

setErrorForwarder

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

Parameters:
pError - the stream

getErrorForwarder

public 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 IOException
Sends the given data to the executed program.

Parameters:
pData - the data
Throws:
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


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.