开发者

Java read Oracle EXP command output

开发者 https://www.devze.com 2023-03-15 07:35 出处:网络
I need to run the Oracle EXP command through a Java program and print somewhere the command output. The EXP command is correct, the dump file is created correctly when I execute my Java code, but I\'

I need to run the Oracle EXP command through a Java program and print somewhere the command output.

The EXP command is correct, the dump file is created correctly when I execute my Java code, but I'm experiencing some issues to get the output.

This is an snippet very similar to the one I'm using to read the output:

String line;
String output = "";
try {
    Process p = Runtime.getRuntime().exec(myCommand);
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
  开发者_JAVA技巧      output += (line + '\n');
    }
    input.close();
}
catch (Exception ex) {
    ex.printStackTrace();
}
System.out.println(output);

As I said, the command is correctly executed (verified through the generated dump file), but nothing appears on my console and my Java programs doesn't terminate either.

The same code works perfectly if I use another command, as "ls -l" instead of "exp ...".


Maybe exp is writing to standard error output rather than standard output.

Try to use p.getErrorStream() instead of getInputStream()


As a_horse_with_no_name said, it might be that the error stream buffer is full and thus is blocking the programm execution.

Either try to start a Thread to also read the error stream or use the ProcessBuilder class to redirect the error stream to stdout (which you already read).

0

精彩评论

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