I am using java process to start a system command in windows
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmdString);
I want to get the prompt out put from cmdString = "cmd /c type fileSmallSize"->>>> It is ok the have the content of the file when file is small.
However, for a large file java process will hang and no Exception occurred, what is the problem?
The easiest testing you can try on the logging.properties file in java.
Need help to find out
public static String executeCmdAndReturnPromptResult(String cmdString)
throws Exception {
LOGGER.entering(CLASSNAME,
"Entering executeCmdAndReturnPromptResult()", cmdString);
String cmd = cmdString;
LOGGER.info("The system command: " + cmd);
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmd);
LOGGER.info("Error: " +getStringFromInputStream(pr.getErrorStream()));
int exitVal = pr.waitFor();
// System.out.println("ExitCode cmd return = " + exitVal);
LOGGER.info("ExitCode cmd return = " + exitVal);
// String s = "";
java.io.InputStream input = pr.getInputStream();
BufferedInputStream buffer = new BufferedInputStream(input);
BufferedReader commandResult = new BufferedReader(
new InputStreamReader(buffer));
StringBuilder sb = new StringBuilder();
String line = "";
try {
while ((line = commandResult.readLine()) != null) {
sb.append(line+ "\n") ;
System.out.println("Emcli info: "+ sb.toString());
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if (commandResult!=null){
commandResult.close();
}
}
System.out.println("The prompt from the cmd -> " + sb.toString());
LOGGER.exiting(CLASSNAME, "Exiting executeCmdAndReturnPromptResult()",
sb.toString());
return sb.toString().trim();
}
It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?
My question now is how to increase the size of buffer in order to read a larger InputStream ?
BufferedInputStream() default size is
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;
How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not help!