🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
4 messages
4 total messages Started by George Mon, 21 Jun 2004 20:22
reading standard output
#159
Author: George
Date: Mon, 21 Jun 2004 20:22
19 lines
1810 bytes
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());
        }
Re: reading standard output
#160
Author: Lori M Olson [TeamB]
Date: Mon, 21 Jun 2004 20:39
45 lines
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
Re: reading standard output
#161
Author: 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]
Re: reading standard output
#162
Author: George
Date: Tue, 22 Jun 2004 14:13
86 lines
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]
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads