1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public class Sample127 {
    public static void main(String[] args) {
        try {
            ProcessBuilder builder = new ProcessBuilder("ipconfig", "/all");
            Process process = builder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                if (line.length() == 0) continue;
                System.out.println(line);
            }

            int ret = process.waitFor();
            System.out.println("ExitValue=" + ret);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}