Java exec execCommand(String command)

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

Description

exec Command

License

Open Source License

Declaration

private static String execCommand(String command) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Main {
    private static String execCommand(String command) {
        String result = null;//from   w ww .ja  v a  2s .  c om
        String newLine = System.getProperty("line.separator");
        try {
            Process p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            StringBuilder response = new StringBuilder();
            String line = reader.readLine();
            while (line != null) {
                response.append(line + newLine);
                line = reader.readLine();
            }
            result = response.toString();
        } catch (Exception e) {
            result = null;
        }
        return result;
    }
}

Related

  1. execCmd(String cmd)
  2. execCmd(String cmd, File where)
  3. execCmd(String command)
  4. execCmdWindows(String cmd)
  5. execCommand(String cmd)
  6. execCommand(String command)
  7. execCommand(String[] cmd)
  8. execCommand(String[] cmd)
  9. execCommandLineUtility(String cmd)