🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #161

Re: reading standard output

#161
From: Lori M Olson [TeamB]
Date: Mon, 21 Jun 2004 20:49
46 lines
2656 bytes
Lori M Olson [TeamB] wrote:

> George wrote:
> 
>> I want to capture the standard output of a console program written in 
>> C in a
>> JTextArea component.  The code I am running is shown below.  The issue I
>> have is:  it takes inordinately long for the the first line of    
>> output to
>> appear; and when it does all of the ouput (about 20 lines) appears 
>> together.
>> This is not the case if I run the program from the DOS prompt.  Any ideas
>> why the behavior is different when the program is run under control of a
>> Java program?
>>
>>      cycleProcess = rt.exec(command, null, currentDir);
>>         InputStreamReader isr = new
>> InputStreamReader(cycleProcess.getInputStream());
>>         batchLogReader = new LineNumberReader(isr);
>>         outputLine = batchLogReader.readLine();
>>         while (outputLine  != null) {
>>           outputLine = batchLogReader.readLine();
>>           messagesTextArea.setText(messagesTextArea.getText() + "\n" +
>> outputLine);
>>           
>> messagesTextArea.paintImmediately(messagesTextArea.getBounds());
>>         }
>>
>>
> 
> Generally streams don't flush to output until their buffers are full. If 
> you want to see intermediate results, you should use flush().
> 

Oops.  That's not an output stream.  Sorry.

You are doing screen update work in your main thread, which is not going 
to work.  You should investigate the usage of SwingUtilities.invokeLater.

http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

-- 

Regards,

Lori Olson [TeamB]
Technical Details
Message-ID: <40d74a22$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40d74327@newsgroups.borland.com> <40d747a9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,62c0f62159aba6f6
X-Google-Attributes: gid1089d0,public
Date: Mon, 21 Jun 2004 14:49:50 -0600
From: "Lori M Olson [TeamB]" <javadragon@techie.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax; CDonDemand-Dom)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: reading standard output
References: <40d74327@newsgroups.borland.com> <40d747a9$1@newsgroups.borland.com>
In-Reply-To: <40d747a9$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 142.179.181.200
Message-ID: <40d74a22$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1087851042 142.179.181.200 (21 Jun 2004 13:50:42 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail