2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Javaでコマンドを実行する(ping)

Last updated at Posted at 2018-01-06
String cmd = "cmd.exe /c ping 8.8.8.8"; //実行するコマンド

Runtime runtime = Runtime.getRuntime();

Process p = runtime.exec(cmd);

InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "Shift-JIS");
BufferedReader reader = new BufferedReader(isr);

for (String line; (line = reader.readLine()) != null;) {
	System.out.println(line);
}

出力

8.8.8.8 に ping を送信しています 32 バイトのデータ:
8.8.8.8 からの応答: バイト数 =32 時間 =15ms TTL=57
8.8.8.8 からの応答: バイト数 =32 時間 =13ms TTL=57
8.8.8.8 からの応答: バイト数 =32 時間 =12ms TTL=57
8.8.8.8 からの応答: バイト数 =32 時間 =13ms TTL=57

8.8.8.8 の ping 統計:
    パケット数: 送信 = 4、受信 = 4、損失 = 0 (0% の損失)、
ラウンド トリップの概算時間 (ミリ秒):
    最小 = 12ms、最大 = 15ms、平均 = 13ms
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?