public class RuntimeUtil extends Object
| Constructor and Description |
|---|
RuntimeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
gc()
This method guarantees that garbage collection is
done unlike
|
static void |
gc(int count)
calls
count times |
static void |
gcOnExit()
This method guarantees that garbage colleciton is
done after JVM shutdown is initialized
|
static String |
getPID()
Returns the PID of the current process.
|
static void |
redirectStreams(Process process,
OutputStream output,
OutputStream error)
Redirects given process's input and error streams to the specified streams.
|
static String |
runCommand(String command)
Runs the specified
command in terminal (sh in *nix/cmd in windows) and
returns the command output. |
static String |
runCommand(String command,
String[] envp,
File workingDir)
Runs the specified
command in terminal (sh in *nix/cmd in windows) and
returns the command output. |
public static void redirectStreams(Process process, OutputStream output, OutputStream error)
process - process whose streams to be redirectedoutput - outputStream to which process's inputStream is redirected.error - outputStream to which process's errorStream is redirected.public static String runCommand(String command, String[] envp, File workingDir) throws IOException
command in terminal (sh in *nix/cmd in windows) and
returns the command output.command - complete command to be executedenvp - array of strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.workingDir - the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.IOException - If an I/O error occursrunCommand(String)public static String runCommand(String command) throws IOException
command in terminal (sh in *nix/cmd in windows) and
returns the command output. The subprocess created inherits environment and working
directory from the current processcommand - complete command to be executedIOException - If an I/O error occursrunCommand(String, String[], java.io.File)public static String getPID() throws IOException
"pid"IOException - If an I/O error occurspublic static void gc()
System.gc()public static void gc(int count)
gc() count timespublic static void gcOnExit()
Copyright © 2021. All rights reserved.