Article View: borland.public.jbuilder.java.api
Article #162Re: reading standard output
From: George
Date: Tue, 22 Jun 2004 14:13
Date: Tue, 22 Jun 2004 14:13
86 lines
4151 bytes
4151 bytes
Actually the timing issue seems to be in getting back the first line from
the BufferedReader. I put in some print statement into the code which is
shown below: I also show the timings printed out in the JBuilder output
window
cycleProcess = rt.exec(command, null, currentDir);
System.out.println("Starting to read output " + new Date());
InputStreamReader isr = new
InputStreamReader(cycleProcess.getInputStream());
batchLogReader = new LineNumberReader(isr);
System.out.println("Streams created " + new Date());
outputLine = batchLogReader.readLine();
System.out.println("First line received " + new Date());
while (outputLine != null) {
// messagesTextArea.setText(messagesTextArea.getText() + "\n" +
outputLine);
// messagesTextArea.paintImmediately(messagesTextArea.getBounds());
SwingUtilities.invokeAndWait(new OutputHandler());
outputLine = batchLogReader.readLine();
}
System.out.println("All lines received " + new Date());
Here is the sequence of print statements as output in a trial run
Starting to read output Tue Jun 22 10:08:38 EDT 2004
Streams created Tue Jun 22 10:08:38 EDT 2004
First line received Tue Jun 22 10:09:05 EDT 2004
All lines received Tue Jun 22 10:09:06 EDT 2004
As you can see most of the time is spent in waiting for the first line to
arrive.....
"Lori M Olson [TeamB]" <javadragon@techie.com> wrote in message
news:40d74a22$1@newsgroups.borland.com...
> 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:
<40d83e0a$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40d74327@newsgroups.borland.com> <40d747a9$1@newsgroups.borland.com> <40d74a22$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 From: "George" <geo_54321@yahoo.com> Newsgroups: borland.public.jbuilder.java.api References: <40d74327@newsgroups.borland.com> <40d747a9$1@newsgroups.borland.com> <40d74a22$1@newsgroups.borland.com> Subject: Re: reading standard output Date: Tue, 22 Jun 2004 10:13:03 -0400 Lines: 88 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 63.119.115.129 Message-ID: <40d83e0a$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1087913482 63.119.115.129 (22 Jun 2004 07:11:22 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail