I need to run a Batch file from my Java Program and know if that was completed or not.
try{
Process process = Runtime.getRuntime().exec( command );
if( null!=process && process.waitFor() == 0 &&process.exitValue()== 0 )
{
LOGGER.debug("Command executed successfuly.["+command+"]");
return 0;
}
else{
LOGGER.debug( "Error while getting the modified log" );
return 1;
}
}
catch( IOException e ){
// TODO Auto-generated catch block
e.printStackTrace();
}
catch( InterruptedException e ){
// TODO Auto-generated catch block
e.printStackTrace();
}
My command is something similar to this cmd /c C:/Test/test.bat
This test.bat file takes some 10-15 minutes to complete. Immediately after this is executed, process.exitValue() returns 0. But I need to know if this was executed completely or not. In my test.bat file, I'm calling another exe file which performs some operations. That exe file writes some error information to the console.I need to get that information.
Is it possible to know this from Java code? Or Can someone please let me know the best way to check this? I thought of some approaches like writing the status(after successful completion) to a text file (from the batch program) and then check this from Java code. But I don't think that is the correct way to do this.