Java exec executeLocalCommand(String[] command)

Here you can find the source of executeLocalCommand(String[] command)

Description

execute Local Command

License

Open Source License

Declaration

public static String executeLocalCommand(String[] command) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static String executeLocalCommand(String[] command) {
        StringBuffer output = new StringBuffer();

        Process p;/*from  ww w .  j a va  2 s  . c o  m*/
        try {
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }

            reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            line = "";
            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return output.toString();
    }
}

Related

  1. executeDELETE(String parameters)
  2. executeDotCommand(final File dotFile)
  3. executeGET(DataInputStream sockInp, DataOutputStream sockOutp)
  4. executeGetStatus(ProcessBuilder pb)
  5. executeIt(String command)
  6. executeLS()
  7. executeMemoryInfoProcess(String... command)
  8. executeNativeCommand(String command)
  9. executeProcess(final File workDir, final String... termArray)