Article View: borland.public.jbuilder.java.api
Article #160Re: reading standard output
From: Lori M Olson [TeamB]
Date: Mon, 21 Jun 2004 20:39
Date: Mon, 21 Jun 2004 20:39
45 lines
2622 bytes
2622 bytes
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().
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Technical Details
Message-ID:
<40d747a9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40d74327@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:39:17 -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> In-Reply-To: <40d74327@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: <40d747a9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1087850409 142.179.181.200 (21 Jun 2004 13:40:09 -0700) Lines: 46 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail