从Java运行Oracle import命令并查看控制台输出 [英] Run Oracle import Command from Java and see Console output

查看:141
本文介绍了从Java运行Oracle import命令并查看控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为.dmp文件运行Oracle数据库命令,如下所示:

I am running an Oracle database Command for a .dmp file like this:

String impcmd = "imp askul/askul@askdb file=mydumpfile.dmp log=mylogfile.log fromuser=askul touser=askul full=N ignore=Y grants=Y indexes=Y";
Process p = Runtime.getRuntime().exec(impcmd);
p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
while(line != null){
System.out.println(line);
line = br.readLine();
}

数据库导入在后台进行得很好,但是我希望能够在导入进行时看到控制台输出,因为我现在不得不猜测它是否已完成.我在这里想念什么?

The database import is Happening Fine on the Background, but I want to be Able to see the console output as the Import goes on as I now have to guess whether it is complete or not. What Am I missing here?

推荐答案

您需要在单独的线程中捕获stdout和stderr(以防止阻塞),并在获取时将其输出,等待该过程完成完成.

You need to capture the stdout and stderr in separate threads (to prevent blocking) and output this as you get it, whilst waiting for the process to complete.

请注意,您可能需要同时读取stdout stderr.否则,您的输出可能会转到配置的日志文件中.

Note that you may need to read both stdout and stderr. Or your output may be going to the configured log file instead.

有关更多信息和示例代码的引用,请参见此答案.还要查看这篇文章,讨论使用Runtime.exec()

See this answer for more info and references to example code. Also check this article, which discusses common pitfalls when using Runtime.exec()

这篇关于从Java运行Oracle import命令并查看控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆