私の目標は、コンピューター上のすべてのインターネット接続を印刷することです。cmd で netstat と入力すると、インターネット接続リストが表示されます。私は自動的にJavaで同じことをしたいと思っていました。
私のコード:
Runtime runtime = Runtime.getRuntime();
process = runtime.exec(pathToCmd);
byte[] command1array = command1.getBytes();//writing netstat in an array of bytes
OutputStream out = process.getOutputStream();
out.write(command1array);
out.flush();
out.close();
readCmd(); //read and print cmd
しかし、このコードでは C:\eclipse\workspace\Tracker>Mais? 接続のリストの代わりに。明らかに、Windows 7でEclipseを使用しています。何が間違っていますか? 同様のトピックを調べましたが、何が問題なのかわかりませんでした。回答ありがとうございます。
編集:
public static void readCmd() throws IOException {
is = process.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}