mapss.dif.util.command
Class CommandUtilities

java.lang.Object
  extended by mapss.dif.util.command.CommandUtilities

public class CommandUtilities
extends java.lang.Object

A class that included utilities that interact with the command prompt of the underlying operating system. Note that the executions in ExecutionClient are serial executions though the ExecutionServer is a parallel executing server. Therefore each ExecutionServer will be able to accept multiple communications and run their commands in parallel, assuming that its underlying operating system is a multitasking one. In order to have parallel executions on the client side, multiple threads should be created, each including one ExecutionClient.

It is a known problem that the same CommandUtilities object throws an exception if it is used to run more than two local commands. Therefore it is advisable to use a new object for each new local command. (added by Fuat Keceli)

Version:
$Id: CommandUtilities.java 362 2007-02-25 21:08:57Z plishker $
Author:
Shahrooz Shahparnia, the remote execution method is based on a code by Mark Nadelson in the JavaPro magazine. September 2002 issue.

Field Summary
 boolean done
           
 
Constructor Summary
CommandUtilities()
          The default constructor.
 
Method Summary
 java.lang.String getCommandResult()
          Return the execution message the program generates while executing a command using the runRemoteCommand and runCommand methods.
 java.lang.String getErrorMessage()
          Return the error message the program generates while executing a command using the runRemoteCommand and runCommand methods.
 boolean runCommand(java.lang.String[] command)
          Runs a command on the local machine and returns true on zero exit.
 boolean runRemoteCommand(java.lang.String host, int hostPort, java.lang.String[] command)
          Runs a command on a remote machine and returns true on zero exit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

done

public boolean done
Constructor Detail

CommandUtilities

public CommandUtilities()
The default constructor. It does nothing.

Method Detail

getCommandResult

public java.lang.String getCommandResult()
Return the execution message the program generates while executing a command using the runRemoteCommand and runCommand methods.

Returns:
The execution message.

getErrorMessage

public java.lang.String getErrorMessage()
Return the error message the program generates while executing a command using the runRemoteCommand and runCommand methods.

Returns:
The error message.

runRemoteCommand

public boolean runRemoteCommand(java.lang.String host,
                                int hostPort,
                                java.lang.String[] command)
Runs a command on a remote machine and returns true on zero exit.

Parameters:
host - The host on which the ExecutionServer is running on.
hostPort - The port number which the ExecutionServer is listening to.
command - The command and parameters of the command that it going to be executed on the host.
Returns:
True If the program exits with a zero value.

runCommand

public boolean runCommand(java.lang.String[] command)
Runs a command on the local machine and returns true on zero exit.

Parameters:
command - The command and parameters of the command that it going to be executed on the local machine.
Returns:
True If the program exits with a zero value.