如何在Java程序中调用shellscript?
String sCommandString="sh /home/admin/ping.sh";
Process p = Runtime.getRuntime().exec(sCommandString);
最佳答案
运行命令并获取输出的最简单方法:
Process p = Runtime.getRuntime().exec("ls");
p.waitFor();
Scanner s = new Scanner(p.getInputStream());
while (s.hasNextLine()) {
String l = s.nextLine();
System.out.println(l);
}