62,615
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
try {
long fromDate = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec("java gx.RegistClient");
long thruDate = System.currentTimeMillis();
boolean finish = false;
while ((thruDate - fromDate < 120000) && !finish) {
try {
int ret = process.exitValue();
System.out.println("exec cmd result process: " + ret);//这里总是反回 1,我觉得和操作系统控制进程有关?
if (ret == 0) finish = true;
} catch (Exception e) {
System.err.println("exec cmd err: " + e.getMessage());
}
Thread.sleep(500);
thruDate = System.currentTimeMillis();
}
System.out.println("========================总是时间超时,即thruDate - fromDate >120000 跳出while===========================>");
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}