Java exec executeCommandLine(String command)

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

Description

execute Command Line

License

Open Source License

Declaration

public static String[] executeCommandLine(String command) throws IOException, InterruptedException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] executeCommandLine(String command) throws IOException, InterruptedException {
        List<String> lines = new ArrayList<String>();

        String line;/*  w  w  w.j  a v  a 2  s .c om*/
        Process proc;

        proc = Runtime.getRuntime().exec(command);

        BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));

        while ((line = input.readLine()) != null) {
            lines.add(line);
        }

        input.close();

        if (0 == proc.waitFor()) {
            // Succeeded
            proc.destroy();
            return lines.toArray(new String[lines.size()]);
        }

        return lines.toArray(new String[0]);
    }
}

Related

  1. executeCommand(String[] command, boolean wait)
  2. executeCommand1(boolean isProcessBuilder, String command)
  3. executeCommand2(boolean isProcessBuilder, String command)
  4. executeCommandAndExtractStdOut(String cmd)
  5. executeCommandForceDir(String baseCommand, String osPath, File file)
  6. executeCommandLineReturnAll( final String[] command)
  7. executeCommandLinux(final String _command)
  8. executeDELETE(String parameters)
  9. executeDotCommand(final File dotFile)