Java exec executeCommand(String comand)

Here you can find the source of executeCommand(String comand)

Description

execute Command

License

Apache License

Declaration

public static void executeCommand(String comand) throws IOException, InterruptedException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void executeCommand(String comand) throws IOException, InterruptedException {
        Process p;// w ww  .ja  v a2  s  . c o m

        try {
            p = Runtime.getRuntime().exec(comand);
            p.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            StringBuffer sb = new StringBuffer();

            String line = reader.readLine();
            sb.append(line);
            while (line != null) {
                line = reader.readLine();
                sb.append(line);
                System.out.println(line);
            }

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

Related

  1. executeCommand(final String cmd)
  2. executeCommand(List cmdArray)
  3. executeCommand(List command)
  4. executeCommand(String cmd)
  5. executeCommand(String cmd)
  6. executeCommand(String command)
  7. executeCommand(String command)
  8. executeCommand(String command)
  9. executeCommand(String command)