PROTOTYPE
Not reviewed yet: use at your own risk!
|
satin.common
Class SystemUtils
java.lang.Object
|
+--satin.common.SystemUtils
public class SystemUtils
extends java.lang.Object
Assorted system-level utilities.
- Author:
- Ed Stauff
|
Method Summary |
static int |
exec(java.lang.String command,
java.lang.String[] envVars,
java.io.File workingDir,
java.lang.StringBuffer stdOut,
java.lang.StringBuffer stdErr)
Executes a system command and waits for it to complete. |
static int |
exec(java.lang.String command,
java.lang.StringBuffer stdOut,
java.lang.StringBuffer stdErr)
Executes a system command and waits for it to complete. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SystemUtils
public SystemUtils()
exec
public static int exec(java.lang.String command,
java.lang.String[] envVars,
java.io.File workingDir,
java.lang.StringBuffer stdOut,
java.lang.StringBuffer stdErr)
throws java.io.IOException,
java.lang.InterruptedException
- Executes a system command and waits for it to complete.
Note that this method does not support shell extensions, as the
command is not automatically executed within a shell environment.
Thus, things like pipes and I/O redirection cannot be used
unless you explicitly invoke a shell as part of the command.
Example
StringBuffer dirContents = new StringBuffer();
StringBuffer error = new StringBuffer();
if (0 != SystemUtils.exec("ls -l c:/temp", null, null, dirContents, error))
throw new Error("ls failed: " + error);
// On success, dirContents contains a directory listing of c:/temp.
// On failure, error contains something like:
// "File or directory \"c:/temp\" not found"
- Parameters:
command- the command to be executed.
envVars- an array of strings, each of which contains an
environment variable setting of the form
name=value.
If this parameter is null, the subprocess (command)
inherits its environment from the caller. workingDir- the working directory for the command.
If this parameter is null, the subprocess (command)
inherits its working directory from the caller.
stdOut- the command's standard output will be appended
to this buffer. Pass null if you don't want it.
stdErr- the command's standard error output will be appended
to this buffer. Pass null if you don't want it.
- Returns:
- the exit code of the command, usually 0 on success.
exec
public static int exec(java.lang.String command,
java.lang.StringBuffer stdOut,
java.lang.StringBuffer stdErr)
throws java.io.IOException,
java.lang.InterruptedException
- Executes a system command and waits for it to complete.
Note that this method does not support shell extensions, as the
command is not automatically executed within a shell environment.
Thus, things like pipes and I/O redirection cannot be used
unless you explicitly invoke a shell as part of the command.
Example
StringBuffer dirContents = new StringBuffer();
StringBuffer error = new StringBuffer();
if (0 != SystemUtils.exec("ls -l c:/temp", dirContents, error))
throw new Error("ls failed: " + error);
// On success, dirContents contains a directory listing of c:/temp.
// On failure, error contains something like:
// "File or directory \"c:/temp\" not found"
- Parameters:
command- the command to be executed.
stdOut- the command's standard output will be appended
to this buffer. Pass null if you don't want it.
stdErr- the command's standard error output will be appended
to this buffer. Pass null if you don't want it.
- Returns:
- the exit code of the command, usually 0 on success.
9 July 2001 Ed Stauff - added overloaded exec that takes env and dir.
Generated on 5/9/2001 19:37 from SystemUtils.java (PRIVATE SOURCES)