public class ExecProc {
public static void runExecFile(String execFile) throws IOException 
{
try{
Runtime.getRuntime().exec(execFile);
}catch(Exception ex){
throw new IOException(ex.getMessage());
}
}

public static void runExecFile(String execFile,boolean waitFlag) throws IOException
{
try{
Process proc = Runtime.getRuntime().exec(execFile);
System.out.println("test");
if (waitFlag)
proc.waitFor();
int exitVal = proc.exitValue();
            System.out.println("Process exitValue: " + exitVal); }catch(Exception ex){
throw new IOException(ex.getMessage());
}
}

public static void main(String[] args)
{
try{
runExecFile("exp usr/pwd@sid file = d:\\test.dmp",true);
System.out.println("系统已启动");

}catch(Exception ex){
System.err.println(ex.getMessage());
}
}
}我要怎么控制proc 阿,现在是exp命令可以执行,但是程序始终不退出。
int exitVal = proc.exitValue();//这句始终执行不到
谢谢!

解决方案 »

  1.   

    请问,上面的变量String execFile,
    表示的是一个*.exe文件名吗?
    意思就是说JAVA可以调用EXE这种可执行文件啊!
    那真是太好了!
      

  2.   

    请问楼主是怎么判断这条语句执行不到呢?  -int exitVal = proc.exitValue();
    根据后一句的输出吗?后一句的输出是什么?
      

  3.   

    一旦执行了proc.waitFor();就要等那个exe结束运行了才会继续执行下去。把proc.waitFor()去掉就是了