import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.BufferedReader;

import java.util.ArrayList;


public class tbRobot {
    
    static public String[] runCommand(String cmd) throws IOException {

        // set up list to capture command output lines

        ArrayList list = new ArrayList();

        // start command running

        Process proc = Runtime.getRuntime().exec(cmd);

        // get command's output stream and

        // put a buffered reader input stream on it

        InputStream istr = proc.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(istr));

        // read output lines from command

        String str;
        while ((str = br.readLine()) != null)
            list.add(str);

        // wait for command to terminate

        try {
            proc.waitFor();
        }
        catch (InterruptedException e) {
            System.err.println("process was interrupted");
        }

        // check its exit value

        if (proc.exitValue() != 0)
            System.err.println("exit value was non-zero");

        // close stream

        br.close();

        // return list of strings to caller

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




syntax highlighted by Code2HTML, v. 0.8.11