0

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?

0

2 Answers 2

1

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.

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Man I cant get a thing out of that article.
What precisely is the issue ?
0

I believe you just want to move the call to waitFor.

// p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
while(line != null){
  System.out.println(line);
  line = br.readLine();
}
p.waitFor(); // <-- to here.

4 Comments

Still happenning in the BAckground even after I moved p.waitFor(); to after the while loop.
Are you sure there's console output to get?
If I went to cmd and executed this command, it will show importing table...... 23rows.. Something like this. This is what I want to see.
could the output have gone to stderr?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.