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:
- exec: Execute the command, returning
immediately even if the command is still
running. This would be appropriate
for printing a file.
- 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).
- 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:
Exec.exec("/usr/ucb/lpr Some-File");
Exec.execWait("/usr/local/bin/javac Foo.java");
Exec.execWait("/usr/local/bin/java Foo");
Exec.execPrint("/usr/bin/ls -al");
- Version:
- 1.0 1997
- Author:
- Marty Hall
(
hall@apl.jhu.edu)
-
Exec()
-
-
exec(String)
- Starts a process to execute the command.
-
execPrint(String)
- Starts a process to execute the command.
-
execWait(String)
- Starts a process to execute the command.
-
getVerbose()
- Will Exec print status messages?
-
setVerbose(boolean)
- Determines if the Exec class should print which
commands are being executed, and print error
messages if a problem is found.
Exec
public Exec()
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.
getVerbose
public static boolean getVerbose()
- Will Exec print status messages?
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.
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.
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.