2013年9月6日星期五

java oracle backup command execution total failure , why

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) {
}

commissioning found : Executive p.waitFor () will not move .

above cmd command I run directly from the command line there is no problem .

above program execution mysql mysqldump backup command is also no problem.

------ Solution ------------------------------------ --------
to resolve several issues:
1, getOutputStream ();
2, getErrorStream ();
3, getInputStream (); / / not need to enter this if confirmed , may not care, but at your own risk .
------ Solution ---------------------------------------- ----
exp root/123456 @ testdb file = c :/ zzz2.dat into bat batch script ( to ensure that the implementation can double-click ) , then java.lang.Runtime.getRuntime (). exec ("XXX.bat");
------ Solution ------------------------------- -------------
backup operation is not there display ? Need to print out the contents will be displayed , otherwise I might have been stuck in the place shown . Can do to try:

...
            String s;
            BufferedReader bufferedReader =
                new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((s = bufferedReader.readLine()) != null)
            {
                System.out.println(s);//将回显内容打印出来
            }
...

------ Solution ------------------------------------- -------

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();

------ Solution --------------------------- -----------------
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.


look at this api description to understand ah , there are no child processes to happen?

没有评论:

发表评论