Class Exec

Class Exec

java.lang.Object
   |
   +----Exec

public class Exec
extends Object
A class that eases the pain of running external processes from applications. Lets you run a program three ways:
  1. exec: Execute the command, returning immediately even if the command is still running. This would be appropriate for printing a file.
  2. execWait: Execute the command, but don't return until the command finishes. This would be appropriate for sequential commands where the first depends on the second having finished (e.g. javac followed by java).
  3. execPrint: Execute the command and print the output. This would be appropriate for the UNIX command ls.
Note that the PATH is not taken into account, so you must specify the full pathname to the command, and shell builtin commands will not work. For instance, on Unix the above three examples might look like:
  1. Exec.exec("/usr/ucb/lpr Some-File");
  2.        Exec.execWait("/usr/local/bin/javac Foo.java");
           Exec.execWait("/usr/local/bin/java Foo");
           
  3. Exec.execPrint("/usr/bin/ls -al");
Version:
1.0 1997
Author:
Marty Hall ( hall@apl.jhu.edu)

Constructor Index

 o Exec()

Method Index

 o exec(String)
Starts a process to execute the command.
 o execPrint(String)
Starts a process to execute the command.
 o execWait(String)
Starts a process to execute the command.
 o getVerbose()
Will Exec print status messages?
 o setVerbose(boolean)
Determines if the Exec class should print which commands are being executed, and print error messages if a problem is found.

Constructors

 o Exec
  public Exec()

Methods

 o setVerbose
  public static void setVerbose(boolean verboseFlag)
Determines if the Exec class should print which commands are being executed, and print error messages if a problem is found. Default is true.
Parameters:
verboseFlag - true: print messages. false: don't.
 o getVerbose
  public static boolean getVerbose()
Will Exec print status messages?
 o exec
  public static boolean exec(String command)
Starts a process to execute the command. Returns immediately, even if the new process is still running.
Parameters:
command - The full pathname of the command to be executed. No shell builtins (e.g. "cd") or shell meta-chars (e.g. ">") allowed.
Returns:
false if a problem is known to occur, but since this returns immediately, problems aren't usually found in time. Returns true otherwise.
 o execWait
  public static boolean execWait(String command)
Starts a process to execute the command. Waits for the process to finish before returning.
Parameters:
command - The full pathname of the command to be executed. No shell builtins or shell meta-chars allowed.
Returns:
false if a problem is known to occur, either due to an exception or from the subprocess returning a non-zero value. Returns true otherwise.
 o execPrint
  public static boolean execPrint(String command)
Starts a process to execute the command. Prints all output the command gives.
Parameters:
command - The full pathname of the command to be executed. No shell builtins or shell meta-chars allowed.
Returns:
false if a problem is known to occur, either due to an exception or from the subprocess returning a non-zero value. Returns true otherwise.