Process.exec returning no output - command taking longer than 5 seconds

Joined
Mar 1, 2012
Messages
2
Reaction score
0
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:

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:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top