Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:08:20+00:00 2026-05-26T21:08:20+00:00

I have a Runnable that reads Console output from an externally called exe (see

  • 0

I have a Runnable that reads Console output from an externally called exe (see below) and writes it to both a log file and a JTextArea.

But my Runnable doesn’t show the Console output in the JTextArea until the exe completely finishes. How do I get it to print Console output as it happens?

Short Concise Code Example below:

//Main

import java.awt.*;
import java.io.IOException;
import javax.swing.*;

public class Example extends JFrame {

    private static final long serialVersionUID = 1L; 

    public static int maxX, maxY;

    public static JTextArea ta = new JTextArea(20, 60);//For LOG display window

    public static void main(String args[] ) throws IOException
    {   
        new Example();
    }

    public Example() {

        this.setTitle("Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //MAIN Panel
        final JPanel main = new JPanel();

        JButton RunButton = button.run(main);
        main.add(RunButton);

        Container container = getContentPane();


        container.add(main);
        this.pack();
        this.setVisible(true);
    }


}

//Button Action Listener

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;


public class button {

    public static JButton run( final JPanel parent ) {
        JButton RunButton = new JButton();      
        RunButton.setText("Start!");

        RunButton.addActionListener(
        new ActionListener()
        {
            public void actionPerformed( ActionEvent event)
            {
                try
                {

                    //Set up LOG Display    
                    JDialog dialog = new JDialog((JFrame)null, "Working...");
                    JPanel temp_panel = new JPanel();
                    temp_panel.add(new JScrollPane(Example.ta));
                    dialog.getContentPane().add(temp_panel);
                    dialog.pack();
                    dialog.setVisible(true);

                    //Build the Command
                    ArrayList<String> command = new ArrayList<String>();
                    command.add("ping");
                    command.add("127.0.0.1");

                    //Start the process
                    Process p = new ProcessBuilder(command).start();

                    //Starts LOG display capture in separate thread 
                    SwingUtilities.invokeLater(new execute(p));

                    //Wait for call to complete
                    p.waitFor();
                }
                catch(Exception err)
                {
                    JOptionPane.showMessageDialog( parent, "Error Executing Run!", "Warning", JOptionPane.ERROR_MESSAGE );  
                }

            }//end ActionPerformed
        });
        return RunButton;
    }
}

//Runnable

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class execute implements Runnable {  
    String line;
    Process p; 

    public execute ( Process process ) {
        p = process;
    }

    public void run() {
        try {
            //Read Process Stream Output and write to LOG file
            BufferedReader is = new BufferedReader( new InputStreamReader(p.getInputStream()));

            while ( (line = is.readLine()) != null ) {
                Example.ta.append(line + "\n");
            }   
            System.out.flush();     
        } catch(Exception ex) { ex.printStackTrace(); }  

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:08:20+00:00Added an answer on May 26, 2026 at 9:08 pm

    The problem was not that the thread wasn’t capturing the data, it was the JTextArea just not refreshing. repaint(), revalidate(), and updateUI() did not refresh the JTextArea, but the following did:

    Example.ta.update(Example.ta.getGraphics()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Runnable that gets a line to the Mic, reads from it
I have written a program that constantly reads from the Bluetooth via SPP and
I have the following code in a Runnable that gets passed to a thread
I have a JWindow and a JFrame both I have made runnable and both
I have 52 images that is coming from web URL.I want to display this
I have a button that onclick reads and shows to the user a list
I have an OutputStream that I needed to read from, and so I used
So I have a little app I am working on that scrapes comics from
I have Async Task that must write folder Files from assets to folder on
I have created a Server app that receives sound from client, i then broadcast

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.