|
|
|
Re: Eclipse hangs when I'm running a script [message #493518 is a reply to message #493500] |
Mon, 26 October 2009 15:20 |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
"Henrik Garbergs" <henrik.garbergs@gmail.com> wrote in message
news:hc4cjl$vu7$1@build.eclipse.org...
> This is how the plugin starts the script:
>
> public class scriptListener implements IPatternMatchListenerDelegate {
> ...
> public void matchFound(PatternMatchEvent event) {
> ...
> PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
> public void run() {
> ...
> process = Runtime.getRuntime().exec("myscript "+arguments);
> BufferedReader in = new BufferedReader(new
InputStreamReader(process.getInputStream()));
> BufferedReader err = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
> process.waitFor();
> while((line = in.readLine()) != null)
> output+=(line+"\n");
> ...etc...
>
> How can I find out where the hanging occurs? Is it the "BufferedReader"
that overflows, or maybe the "process.waitFor"?
>
> /Henrik
I can see a number of issues with this snippet. First, you are executing
the script process on the SWT Display thread. This will lock up your GUI
untill the process completes. You should be running the script on a thread
other than the display thread and then use the syncExec call to display the
results in your GUI. The process.waitFor is waiting for the process to
exit. If the process fills up the buffer, it won't exit until you read the
data to empty the buffer. This means that the waitFor method will not
return and you will never get to the code to process the input. Finally,
the loop you have will only process the stdout data from the script. It
will not process the stderr data. You can't process both stdout and stderr
in the same loop without one blocking the other. You will need to kick off
a separate thread to process each stream separately.
|
|
|
|
Powered by
FUDForum. Page generated in 0.09019 seconds