Hi All,
I have java program, which executes a external command and captures/prints the output. This is a simple program and used to work earlier, but after we upgraded to new version(which upgraded the command as well), it has stopped producing ouput (i.e. BufferedReader is empty even though the command executes successfully).
I tried to nail it down and found that the external command now takes longer (<5seconds) than earlier(<1second). I see this similar behavior with "java -version". In other words, if i execute `javac` this snippet works fine, fails only with `java -version`
Given below is the code snippet:
I cannot go with a separate thread (like they use StreamGobbler/StreamEater) because we have this piece of code at about 30 places and creating seperate threads for each would be nightmare.
Can some one suggest a way to handle this?
Regards,
TA
I have java program, which executes a external command and captures/prints the output. This is a simple program and used to work earlier, but after we upgraded to new version(which upgraded the command as well), it has stopped producing ouput (i.e. BufferedReader is empty even though the command executes successfully).
I tried to nail it down and found that the external command now takes longer (<5seconds) than earlier(<1second). I see this similar behavior with "java -version". In other words, if i execute `javac` this snippet works fine, fails only with `java -version`
Given below is the code snippet:
Code:
Process p = Runtime.getRuntime().exec("[COLOR="DarkRed"]java -version[/COLOR]" );
//p.waitFor();
InputStream b = p.getInputStream();
InputStreamReader r = new InputStreamReader(b);
BufferedReader s = new BufferedReader(r);
String data;
while ((data = s.readLine()) != null) {
System.out.println (data);
}
I cannot go with a separate thread (like they use StreamGobbler/StreamEater) because we have this piece of code at about 30 places and creating seperate threads for each would be nightmare.
Can some one suggest a way to handle this?
Regards,
TA
Last edited: