I got some problem trying to launch a process that executes an EXPDP command to make the backup of a Oracle DB.
This is the method that launches the process, the problem is when I try to read from stInput and stdError. The process hangs forever, and if I stop the debug to see where the runtime execution is, the line I get is:
FileInputStream.readBytes(byte[], int, int) line: not available [native method]
At the method entrypoint the value of the cmdCommand parameter is:
"EXPDP system/syspwd@orcl DIRECTORY=DATA_PUMP_DIR SCHEMAS=fabro DUMPFILE=backupFabro.dmp LOGFILE=backupFabro.log"
The method is the following, and it hangs on the first while
loop.
public Boolean cmdCommand(String cmdCommand) throws IOException{
logger.info("**************************************");
logger.info("Esecuzione comando:");
logger.info(cmdCommand);
logger.info("**************************************");
final Process p = Runtime.getRuntime().exec(cmdCommand);
Boolean end = false;
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line = null;
try {
while ((line = stdInput.readLine()) != null) {
logger.info(line);
}
while((line= stdError.readLine()) != null){
logger.error(line);
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
finally{
stdError.close();
stdInput.close();
}
try {
if(p.waitFor() != 0){
logger.error("error etc etc");
}
else{
end = true;
logger.info("success ecc ecc");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
p.destroy();
}
return end;
}