======================exe=======================
try {
Process proc = Runtime.getRuntime().exec(YourCommand);//你的exe文件名
BufferedReader in = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String text = null;
while((text = in.readLine()) != null) {
System.out.println(text);
}
}
catch(IOException ioError) {
ioError.printStackTrace();
System.exit(0);
}
}
}
======================bat=======================
try{
String exeBat ="c:/test.bat";
Process child = Runtime.getRuntime().exec(exeBat);
InputStream in = child.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String line = br.readLine().toString();
while(line!=null ){
System.out.println(line); //输出测试
line = br.readLine().toString();
}
try{
child.waitFor();
br.close();
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}catch (Exception e) {
e.printStackTrace();
}
--转自
该贴由koei123转至本版2015-7-14 11:05:47