在开发过程中执行命令,总是命令执行到一半,就不再执行。开始等待。等所有任务结束后才结束。查资料。用如下方法即可:
Thread t = new Thread() {
@Override
public void run() {
try {
Process process = Runtime.getRuntime().exec(cmd);
InputStream in = process.getInputStream();
BufferedReader inr = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line = null;
while ((line = inr.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
t.start();
try {
//让主线程让一次CPU时间
Thread.sleep(200);
System.out.println();
} catch (InterruptedException e) {
e.printStackTrace();
}