🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problem using Process.waitFor() after exec()

#19830
From: Matthew Hyne
Date: Fri, 05 Dec 1997 00:00
34 lines
1428 bytes
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: <3487A88C.736F96CD@tip.csiro.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,880cdb0fcebe042c,start
X-Google-Attributes: gidf74b3,public
From: Matthew Hyne <mhyne@tip.csiro.au>
Subject: Problem using Process.waitFor() after exec()
Date: 1997/12/05
Message-ID: <3487A88C.736F96CD@tip.csiro.au>
X-Deja-AN: 295401647
Organization: None
Newsgroups: borland.public.jbuilder.java.language