edu.northwestern.at.utils
Class ExecUtils

java.lang.Object
  extended by edu.northwestern.at.utils.ExecUtils

public class ExecUtils
extends java.lang.Object

Execute system commands.


Constructor Summary
protected ExecUtils()
          Don't allow instantiation, do allow overrides.
 
Method Summary
static java.util.ArrayList execAndWait(java.lang.String command, boolean doWait)
          Execute file/command and wait for command to complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecUtils

protected ExecUtils()
Don't allow instantiation, do allow overrides.

Method Detail

execAndWait

public static java.util.ArrayList execAndWait(java.lang.String command,
                                              boolean doWait)
Execute file/command and wait for command to complete.

Parameters:
command - The command or file name to execute.
doWait - True to wait for the command to return.
Returns:
An array list of the output written by the program to standard output, if doWait is true.

Examples:

Windows only directory listing:

ArrayList outputLinesList = execAndWait( "dir" , true );

Directory listing for MacOSX and similar Unixen:

ArrayList outputLinesList = execAndWait( "ls -la" , true );

Open Acrobat file in Acrobat reader, if installed (Windows and MacOSX):

ArrayList outputLinesList = execAndWait( "mydoc.pdf" , false );

Note: On some Unixen and possibly MacOSX, you may need to add a path specifier to get the file "executed." E.g., if the document is in the current directory:

ArrayList outputLinesList = execAndWait( "./mydoc.pdf" , false );

When running a file that causes the associated application to start, and doWait is true, execAndWait may not return until that associated application is closed. You should invoke execAndWait on a separate thread if you want the execute the command and allow your program to continue executing concurrently as well.