java程序读取linux脚本

 

String[] command = {"脚本地址(在linux中的位置)",向脚本中传递的参数};

Process proc = null;

try {

proc = Runtime.getRuntime().exec(command);

BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));

String s = null;

while((s = br.readLine()) != null){

System.out.println(s);

}

} catch (IOException e) {

e.printStackTrace();

System.out.println("IOException while trying to execute " + command);

try {

Thread.sleep(1000);

} catch (InterruptedException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

你可能感兴趣的:(java,thread,linux,脚本)