How do I execute a external command from Java?

This example shows you how to execute a external command from Java.
package net.javaiq.examples.exec;

import java.io.BufferedReader;
import java.io.InputStreamReader;


/**
 * This class demonstrates on how to execute a external command from Java.
 * For example how to execute a batch file from Java or a shell script from Java.
 * @author JavaIQ.net
 * Creation Date Dec 10, 2010
 */
public class ExternalCommandExecutor {
    public static String executeExternalCommand(String[] cmdArray) {
        StringBuffer commandOutput = new StringBuffer("");

        try {
            Process process = Runtime.getRuntime().exec(cmdArray);
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;

            while ((line = input.readLine()) != null) {
                commandOutput.append(line);
                commandOutput.append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return commandOutput.toString();
    }

    /**
     * Method to test other methods in the class with sample inputs
     * @param args
     */
    public static void main(String[] args) {
        String[] cmdArray = new String[1];
        cmdArray[0] = "C:\\test.bat";
        String commandResult = executeExternalCommand(cmdArray);
        System.out.println("Command Result :: " + commandResult);
    }
}