开发者

take time to execute .bat file through java?

i have written a code to run .dat file using Java. but when is run that application then it take time to execute means it give half result and then after some time after gives complete result.

here is my code:

String file = config.getOutPath() + "run_doxygen.bat";
                BufferedWriter out = new BufferedWriter(
                        new FileWriter(file));

                String cmd = "doxygen " + config.getOutPath() + "Doxyfile";
                runtime.exec(cmd);
                System.out.println("cmd_doxy:"+cmd);
                out.write(cmd);
                out.newLine();
                out.close();

开发者_JAVA百科the doxygen generate xml file. let suppose it generate 10 xml file . when i launch that *.bat file it generate 5 file and to generate rest 5 file it take time. and *.bat file contain : doxygen "path"

path is location of config file. it work fine when i run it with cmd or double click.

anybody have any idea . thanks


May be you should flush the writer.

out.newLine();
out.flush();
out.close();


It is not entirely clear what you intend your program to do, but what it is actually is doing is as follows:

  1. It opens the ".bat" file for writing.
  2. It launches a "doxygen" command as a separate external process.
  3. It writes the command to standard output, and then the file.

If you are saying that it takes some time for the output to be written to the file, well that is not entirely unexpected. The operating system may decide to give the newly launched doxygen application a big chunk of CPU time to get started. If it doesn't block, your Java application may not get a time-slice for a few seconds. And after that, the OS may switch between the two applications until one or the other finishes.

But why does it matter? Does your Java application expect / require doxygen to finish before it does?

If so, then the solution is to do something like this:

Process proc = runtime.exec(cmd);
// do more stuff.
int rc = proc.waitFor();
// Whoopee!  the process has finished (or died) check the rc to see which.


if you are not consuming the streams generated by the external command, it can cause the program to hang. See this article which pretty much covers all the gotchas of using Runtime.exec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜