Add tags

Add tags to the following comment

Windowsで、『ipconfig /all』を実行しその結果を受け取ってみました。 実行結果のリターンコードは、Process#exitValue()で取得できます。Process#waitFor() では終了するのを待ってリターンコードを返します。 別プロセスが出力した標準出力を受け取る方法は、Process#getInputStream() で標準出力を受け取れます。Process#getErrorStream() で標準エラーを受け取れます。

 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();
        }
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...