strCmd = new String("cmd /c exp root/123456@testdb file=c:/zzz2.dat"); try {
    Process p = java.lang.Runtime.getRuntime().exec(strCmd );
    while (true) {
     if (p.waitFor() == 0)
      break;
    }
   } catch (Exception e) {
}调试时发现: 执行p.waitFor() 就不动了。以上cmd命令我直接在命令行下执行就没有问题。以上程序执行mysql备份命令mysqldump也没有问题。

解决方案 »

  1.   

    要解决好几个问题:
    1、getOutputStream();
    2、getErrorStream();
    3、getInputStream(); // 这个如果确认不需要输入,可以不管,但风险自担。
      

  2.   

    exp root/123456@testdb file=c:/zzz2.dat放到bat批处理脚本里(要保证能双击执行),然后java.lang.Runtime.getRuntime().exec("XXX.bat");
      

  3.   

    备份操作是不是会有显示?需要将显示内容打印出来,不然可能一直阻塞在显示的地方。可以这么做试试:...
                String s;
                BufferedReader bufferedReader =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
                while ((s = bufferedReader.readLine()) != null)
                {
                    System.out.println(s);//将回显内容打印出来
                }
    ...
      

  4.   


    Process p = java.lang.Runtime.getRuntime().exec(strCmd );
    InputStream is = p.getErrorStream();
    if (is == null) {
               sys.out("错误!");
    }
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    while ((br.readLine()) != null) {
    }
    br.close();
    isr.close();
    is.close();
    exitValue = String.valueOf(p.waitFor());
    p.destroy();
      

  5.   

    waitFor
    public abstract int waitFor()
                         throws InterruptedException
    Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits. Returns:
    the exit value of the subprocess represented by this Process object. By convention, the value 0 indicates normal termination. 
    看看这个api的说明就明白了啊,有没有子进程出现呢?