de.fu_berlin.ties.util
Class ExternalCommand

java.lang.Object
  extended byde.fu_berlin.ties.util.ExternalCommand

public class ExternalCommand
extends Object

A simple wrapper for external scripts or programs. Calls an external program with arguments and environment settings as specified and returns the output of the program.

This class is thread-safe as each call to execute() creates another instances of the program. It uses the default TaskRunner. To allow efficient thread re-use, it is highly recommended to initially register your interest in the default task runner and to finally deregister when you no longer need it.

Version:
$Revision: 1.3 $, $Date: 2004/02/25 16:23:28 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
ExternalCommand(String[] cmdArray)
          Creates a new instance, without specifying environment parameters and working directory.
ExternalCommand(String[] cmdArray, File workDir)
          Creates a new instance, without specifying environment parameters.
ExternalCommand(String[] cmdArray, String[] envparams, File workDir)
          Creates a new instance.
 
Method Summary
 String execute()
          Executed the external command any further arguments and without sending input and returns its output (standard out).
 String execute(CharSequence input)
          Executed the external command without any further arguments and returns its output (standard out).
 String execute(String[] furtherArguments)
          Executed the external command without sending input and returns its output (standard out).
 String execute(String[] furtherArguments, CharSequence input)
          Executed the external command and returns its output (standard out).
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExternalCommand

public ExternalCommand(String[] cmdArray)
                throws IllegalArgumentException
Creates a new instance, without specifying environment parameters and working directory. Communication with the external process occurs in several parallel threads using the default TaskRunner for asynchronous tasks.

Parameters:
cmdArray - array containing the command to call and its general arguments, i.e. arguments that should be used used every time the program is called
Throws:
IllegalArgumentException - if the cmdArray is empty, i.e. the command name is missing

ExternalCommand

public ExternalCommand(String[] cmdArray,
                       File workDir)
                throws IllegalArgumentException
Creates a new instance, without specifying environment parameters. Communication with the external process occurs in several parallel threads using the default TaskRunner for asynchronous tasks.

Parameters:
cmdArray - array containing the command to call and its general arguments, i.e. arguments that should be used used every time the program is called
workDir - the working directory of the process; or null if the command should inherit the working directory of the current process
Throws:
IllegalArgumentException - if the cmdArray is empty, i.e. the command name is missing

ExternalCommand

public ExternalCommand(String[] cmdArray,
                       String[] envparams,
                       File workDir)
                throws IllegalArgumentException
Creates a new instance. Communication with the external process occurs in several parallel threads using the default TaskRunner for asynchronous tasks.

Parameters:
cmdArray - array containing the command to call and its general arguments, i.e. arguments that should be used used every time the program is called
envparams - an array of strings, each element of which has environment variable settings in format name=value; might be null or empty
workDir - the working directory of the process; or null if the command should inherit the working directory of the current process
Throws:
IllegalArgumentException - if the cmdArray is empty, i.e. the command name is missing
Method Detail

execute

public String execute()
               throws IOException
Executed the external command any further arguments and without sending input and returns its output (standard out). Messages written to the standard error stream (stderr) are logged as info statements. The system-specific default character set is used for conversion between strings and streams.

Returns:
the output returned by the command's standard output stream.
Throws:
IOException - if an I/O error occurs

execute

public String execute(CharSequence input)
               throws IOException
Executed the external command without any further arguments and returns its output (standard out). Messages written to the standard error stream (stderr) are logged as info statements. The system-specific default character set is used for conversion between strings and streams.

Parameters:
input - the input to send to the command's standard input stream; or null if no input should be sent
Returns:
the output returned by the command's standard output stream.
Throws:
IOException - if an I/O error occurs

execute

public String execute(String[] furtherArguments)
               throws IOException
Executed the external command without sending input and returns its output (standard out). Messages written to the standard error stream (stderr) are logged as info statements. The system-specific default character set is used for conversion between strings and streams.

Parameters:
furtherArguments - an array of further arguments to use for this single call, might be null; appended after the general arguments specified in the constructor
Returns:
the output returned by the command's standard output stream.
Throws:
IOException - if an I/O error occurs

execute

public String execute(String[] furtherArguments,
                      CharSequence input)
               throws IOException
Executed the external command and returns its output (standard out). Messages written to the standard error stream (stderr) are logged as info statements. The system-specific default character set is used for conversion between strings and streams.

Parameters:
furtherArguments - an array of further arguments to use for this single call, might be null; appended after the general arguments specified in the constructor
input - the input to send to the command's standard input stream; or null if no input should be sent
Returns:
the output returned by the command's standard output stream.
Throws:
IOException - if an I/O error occurs

toString

public String toString()
Returns a string representation of this object.

Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.