🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19730

Re: Problem using Process.waitFor() after exec()

#19730
From: Joe Ryan
Date: Sun, 21 Dec 1997 00:00
41 lines
1790 bytes
Is this code segment from a thread ?
I have had problems with BufferedReader and PrintWriter Streams in a
thread.
Joe Ryan

Matthew Hyne wrote:

> I have a peace of code that executes an application and places it's
> STDOUT and STDERR into a Java Frame.
>
> The problem is, that after executing exec(application) I need to wait
> for it to finish before I read the buffer but waitFor() never seems to
> return.
>
> If I replay waitFor() with a delay the program works for most
> applications - BUT WHY doesn't waitFor() work !!!
>
> I have placed an except of the code below
>
> Process process = Runtime.getRuntime().exec(command_string);
>
> // Capture output
> BufferedReader proc_output =
>   new BufferedReader(new InputStreamReader(
>   new BufferedInputStream(process.getInputStream())));
>
> BufferedReader proc_error =
>   new BufferedReader(new InputStreamReader(
>   new BufferedInputStream(process.getErrorStream())));
>
> process.waitFor();
>
> // For testing we use the below to simulate above
> //Thread.currentThread().sleep(2000);
>
> while (proc_output.ready())
>   textout.addLine(proc_output.readLine()+"\n");
>
> while (proc_error.ready())
>   textout.addLine(proc_error.readLine()+"\n");
Technical Details
Message-ID: <349DC8C8.77DB096D@home.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3487A88C.736F96CD@tip.csiro.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,880cdb0fcebe042c
X-Google-Attributes: gidf74b3,public
From: Joe Ryan <ryanjoe@home.com>
Subject: Re: Problem using Process.waitFor() after exec()
Date: 1997/12/21
Message-ID: <349DC8C8.77DB096D@home.com>
X-Deja-AN: 309205913
Content-Transfer-Encoding: 7bit
References: <3487A88C.736F96CD@tip.csiro.au>
Content-Type: text/plain; charset=us-ascii
Organization: None
Mime-Version: 1.0
Reply-To: ryanjoe@home.com
Newsgroups: borland.public.jbuilder.java.language