horiuchi #5458(2008/01/26 06:51 GMT) [ Java ] Rating1/1=1.00
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(); } } }
Rating1/1=1.00-0+
[ reply ]
horiuchi
#5458()
[
Java
]
Rating1/1=1.00
Windowsで、『ipconfig /all』を実行しその結果を受け取ってみました。 実行結果のリターンコードは、Process#exitValue()で取得できます。Process#waitFor() では終了するのを待ってリターンコードを返します。 別プロセスが出力した標準出力を受け取る方法は、Process#getInputStream() で標準出力を受け取れます。Process#getErrorStream() で標準エラーを受け取れます。
Rating1/1=1.00-0+
[ reply ]