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

voidexecute(String command, Process p, String[] output, boolean cmdStatus)
execute
outputStr = new StringBuffer();
errStr = new StringBuffer();
output[0] = "";
statusFlag = false;
InputStream is = p.getInputStream();
OutputStream os = p.getOutputStream();
InputStream es = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
...
voidexecute(String url)
Tries to launch the application associated to the file..
boolean windows = isWindowsPlatform();
String cmd = null;
try {
    if (windows) {
        cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
        Process p = Runtime.getRuntime().exec(cmd);
    } else {
        cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
...
voidexecute(String... cmdarray)
execute
checkState(cmdarray.length > 0);
try {
    Process process = Runtime.getRuntime().exec(cmdarray);
    process.waitFor();
    checkState(process.exitValue() == SUCCESS_EXIT_CODE, "%s exited with status code: %s", cmdarray[0],
            process.exitValue());
} catch (IOException | InterruptedException e) {
    throw new RuntimeException(e);
...
Collectionexecute(String... command)
Execute a system command and return the output in a String array.
Process p = Runtime.getRuntime().exec(command);
Collection<String> output = new ArrayList<>();
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
    String line;
    while ((line = input.readLine()) != null) {
        output.add(line.trim());
return output;
voidexecute(String... commands)
execute
Process process = null;
try {
    process = Runtime.getRuntime().exec(commands);
    BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = null;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (process != null) {
        process.destroy();
booleanexecute(String[] _command, String _workingDir)
execute
try {
    Process p = Runtime.getRuntime().exec(_command, null, new File(_workingDir));
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = "";
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    int exitVal = p.waitFor();
...
Processexecute(String[] command, File directory, String[] env)
execute
return Runtime.getRuntime().exec(command, env, directory);
BufferedReaderexecute(String[] commandArray)
execute
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(commandArray, null, null);
waitForCompletion(process);
return new BufferedReader(new InputStreamReader(process.getInputStream()));
Stringexecute(Template template, Map rootMap)
execute
Writer out = new BufferedWriter(new OutputStreamWriter(System.out));
StringWriter out2 = new StringWriter();
try {
    template.process(rootMap, out);
    template.process(rootMap, out2);
    out.flush();
    out2.flush();
    out2.close();
...
voidexecute1(final String appPath)
execute
Runtime runtime = Runtime.getRuntime();
runtime.exec("rundll32 url.dll,FileProtocolHandler \"" + appPath + "\"");