util
Class CommandLine

java.lang.Object
  extended by util.CommandLine

public class CommandLine
extends java.lang.Object

Supports the execution of commands as they would work in a bash shell environment. This is different from using Runtime: multiple commands can be issued, and environment variables can be set. Also, input and output streams can be used. Can easily be extended to emulate other shells.

Author:
dgorur

Field Summary
static java.lang.String[] DEFAULT_SHELL_COMMAND
          Default behaviour is to invoke a bash shell just as if it were a login shell, ready to accept commands.
 
Constructor Summary
CommandLine()
          Default constructor.
CommandLine(java.lang.String[] shellCommand)
          Constructs a command line and invokes the given shell commands, specified as a String array.
 
Method Summary
 void exec(java.lang.String command)
          Executes the given command, interpreted just as if it were typed into a bash shell.
 void exec(java.lang.String[] cmdArray)
          Executes an array of commands by concatenating them into a single command.
 java.lang.String getError()
          Returns the buffered error output of this process.
 java.io.InputStream getInputStream()
          Returns the input stream of this process.
 java.lang.String getOutput()
          Returns the buffered output of this process.
 java.io.OutputStream getOutputStream()
          Returns the output stream of this process.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SHELL_COMMAND

public static final java.lang.String[] DEFAULT_SHELL_COMMAND
Default behaviour is to invoke a bash shell just as if it were a login shell, ready to accept commands.

Constructor Detail

CommandLine

public CommandLine()
Default constructor. Creates a bash shell.


CommandLine

public CommandLine(java.lang.String[] shellCommand)
Constructs a command line and invokes the given shell commands, specified as a String array.

Parameters:
shellCommand - the set of desired shell commands.
Method Detail

main

public static void main(java.lang.String[] args)

exec

public void exec(java.lang.String command)
Executes the given command, interpreted just as if it were typed into a bash shell.

Parameters:
command - the desired command.

exec

public void exec(java.lang.String[] cmdArray)
Executes an array of commands by concatenating them into a single command.

Parameters:
cmdArray - the given array of commands.

getError

public java.lang.String getError()
Returns the buffered error output of this process.

Returns:
the buffered error output of this process.

getInputStream

public java.io.InputStream getInputStream()
Returns the input stream of this process. Note: this is actually the output of the process.

Returns:
the input stream of this process.

getOutput

public java.lang.String getOutput()
Returns the buffered output of this process.

Returns:
the buffered output of this process.

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the output stream of this process. Note: this is actually the input to the process.

Returns:
the output stream of this process.