Java Utililty Methods exec

List of utility methods to do exec

Description

The list of methods to do exec are organized into topic(s).

Method

booleanexecute2(final String appPath)
execute
try {
    Runtime runtime = Runtime.getRuntime();
    runtime.exec(appPath);
} catch (IOException | SecurityException | NullPointerException | IllegalArgumentException e) {
    e.printStackTrace();
    return false;
return true;
...
voidexecuteAndWait(String command)
execute And Wait
try {
    Process proc = Runtime.getRuntime().exec(command);
    int returnCode = proc.waitFor();
    if (returnCode != 0) {
        throw new IllegalStateException(
                "Could not execute " + command + ", process returned " + returnCode);
} catch (InterruptedException e) {
...
voidexecuteApplication(String filePath)
execute Application
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("java", "-jar", filePath);
processBuilder.start();
booleanexecuteBashScriptWithParams(ArrayList script)
execute Bash Script With Params
try {
    ProcessBuilder pb = new ProcessBuilder(script);
    final Process process = pb.start();
    process.waitFor();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String result = br.readLine();
...
voidexecuteBatFile(String batFile)
execute Bat File
Runtime runtime = Runtime.getRuntime();
runtime.exec(batFile);
StringexecuteCD(String dirPath)
execute CD
String retStatus = null;
try {
    if (dirPath.equals("..")) {
        File curr = new File(executePWD());
        if (curr.getAbsoluteFile().getParent() != null)
            System.setProperty(ROOT, curr.getAbsoluteFile().getParent());
        else
            System.out.println("::: Reached root directory :::" + ROOT);
...
StringexecuteCmdCommand(String command)
execute Cmd Command
System.out.println("Execute " + command);
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
while (true) {
    line = r.readLine();
...
BufferedReaderexecuteCmdForReader(String cmd)
execute Cmd For Reader
Process pro = Runtime.getRuntime().exec(cmd);
BufferedReader bufReader = new BufferedReader(new InputStreamReader(pro.getInputStream(), "UTF-8"));
return bufReader;
ProcessexecuteComand(String[] comand)
execute Comand
return Runtime.getRuntime().exec(comand);
StringexecuteCommand(final ProcessBuilder pb)
execute Command
final StringBuffer output = new StringBuffer();
Process p;
try {
    p = pb.start();
    final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = "";
    while ((line = reader.readLine()) != null) {
        output.append(line + "\n");
...