Java exec execCmd(String command)

Here you can find the source of execCmd(String command)

Description

exec Cmd

License

Open Source License

Declaration

public static String execCmd(String command) 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static String execCmd(String command) {
        BufferedReader br = null;
        StringBuffer stringBuffer = new StringBuffer();
        try {/*www .  j  av a  2  s . co m*/
            Process p = Runtime.getRuntime().exec(command);
            br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                if ("".equals(line.trim()))
                    continue;

                stringBuffer.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return stringBuffer.toString();
    }
}

Related

  1. execAdbCmd(String cmd)
  2. execAndGetOutput(ProcessBuilder builder)
  3. execCmd(String cmd)
  4. execCmd(String cmd)
  5. execCmd(String cmd, File where)
  6. execCmdWindows(String cmd)
  7. execCommand(String cmd)
  8. execCommand(String command)
  9. execCommand(String command)