命令为正常命令,在WINDOWS命令行下运行成功并自动退出EXP可是在JAVA中运行 Process proc = Runtime.getRuntime().exec(cmd);
后EXP却不自动退出。这到底是什么原因呢?因为我要实现运行Oracle备份后,返回一个是否备份成功的布尔类型。要用到: proc.waitFor(); 等待Runtime开辟的进程结束后返回。但是执行时EXP不退出进程就不结束,程序就 处于一直运行状态。到底是什么原因导致的呢?还是有什么别的方法能实现我的功能呢?
后EXP却不自动退出。这到底是什么原因呢?因为我要实现运行Oracle备份后,返回一个是否备份成功的布尔类型。要用到: proc.waitFor(); 等待Runtime开辟的进程结束后返回。但是执行时EXP不退出进程就不结束,程序就 处于一直运行状态。到底是什么原因导致的呢?还是有什么别的方法能实现我的功能呢?
public boolean executeExp() throws IOException, InterruptedException{
String cmds = "cmd /C exp username/password@ip/sid file=d:/XXXXX.dmp";
boolean shouldClose=false;
boolean res = false;
Process process = Runtime.getRuntime().exec(cmds);
try {
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
if((line.indexOf("EXP-")!=-1)||(line.indexOf("error")!=-1)||(line.indexOf("错误")!=-1)){//这个出错的信息根据不同的oracle版本做相应的改动
shouldClose=true;
break;
}
}
}
catch (IOException ioe) {
shouldClose=true;
}
if(shouldClose){
process.destroy();
}else{
if(process.waitFor()==0){
res = true;
process.destroy();
}
}
return res;
}