0
我試圖通過我的Java應用程序執行網絡測試應用程序。下面是代碼:在Java應用程序中執行命令執行問題
try {
String file = new File("iperf3.exe").getCanonicalPath();
String cmd[] = {file,"-c ping.online.net -P 20 -w 710000 -t"};
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
lblConsole.setText(line);
//System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我得到一個錯誤,說應用程序無法連接到服務器。但是,當我在命令提示符下執行命令時,沒有錯誤。
我可以知道我在這裏錯過了什麼嗎?
您是否在'iperf3.exe'的相同路徑中運行此java代碼。 –
是的。他們在同一個文件夾中 –
管理解決此問題。主要是關於我如何在cmd中執行代碼。剛剛更新爲如下 String file = new File(「iperf3.exe」)。getCanonicalPath(); \t \t \t \t \t String cmd1 [] = {file,「 - c」,「ping.online.net」,「 - P」,「10」,「 - w」,「710000」}; –