views:

72

answers:

1

Hi!

I develop an Eclipse plugin and I have a problem

My code is the following one:

String run_pelda = "cmd.exe /C pelda.exe";
Runtime pelda_rt = Runtime.getRuntime();
Process pelda_proc = javacheckgen_rt.exec(run_pelda);

And after I would like to read the inputstream:

InputStream toolstr = tool_proc.getInputStream();
InputStreamReader r = new InputStreamReader(toolstr);
BufferedReader in = new BufferedReader(r);

But my new Eclipse instsnce freezes. I think I should do it in java threads, but unfortunatelly I don't know to use it correctly.

Please give me some ideas!

A: 

Hi Norbiprog. Take a look the excellent article When Runtime.exec() won't from JavaWorld and see if it helps. In particular, this is probably your culprit:

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

The article provides various ways to address this problem, including the source code for a StreamGobbler class that consumes stderr and stdout in background threads.

It's amazing how well this article has held up. It was originally written in 2000 and I find just about all of it to still be accurate.

Matt Solnit