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

  • SEARCH
  • Home
  • 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 6146559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:58:02+00:00 2026-05-23T18:58:02+00:00

Why I get the output of the process after the process has terminated? I

  • 0

Why I get the output of the process after the process has terminated? I need to get the process output “live”, while the process is running and not after the process has terminated. I would like to run a process like a jboss, which is logging on the standard output, so I need that information in time, and not after the process has terminated. Thank you for answers.

Here is my code:

        try {
        process = processBuilder.start();
        processOutput = process.getOutputStream();
        processInput = process.getInputStream();
        processReader = new BufferedReader(new InputStreamReader(
                processInput));
        processWriter = new BufferedWriter(new OutputStreamWriter(
                processOutput));

        while ((line = processReader.readLine()) != null) {
            System.out.println(line);
          }
        processReader.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Extension:

So I would like to run an external program from an eclipse plug-in with a button. When I click to the button, the program start and the output of the external program will go back to the console. When I click to the stop, the program stops. So here is how I make the instance of the process builder. And I made an example class to test the process builder without start the whole plugin project in every modification.

Here is my process builder instance which is implements the Runnable:

@Override
public void run() {
    List<String> command = new ArrayList<String>();
    command.add(serverPath);
    command.add(String.valueOf(count));
    command.add(filePath);
    processBuilder = new ProcessBuilder(command);
    processBuilder.redirectErrorStream(true);

    try {
        process = processBuilder.start();
        processOutput = process.getOutputStream();
        processInput = process.getInputStream();
        processReader = new BufferedReader(new InputStreamReader(
                processInput));
        processWriter = new BufferedWriter(new OutputStreamWriter(
                processOutput));

        System.out.println(process.waitFor());
        while ((line = processReader.readLine()) != null) {
            System.out.println(line);

        }
        processReader.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

The parameters are come in the constructor. And here is the instantiation:

public static void main(String[] args) throws Exception

{

 SimulationProcess smp = new SimulationProcess(count, "file",
            "program_name");
    smp.run();

}

  • 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-23T18:58:03+00:00Added an answer on May 23, 2026 at 6:58 pm

    There are a few things you can try to resolve your issue:

    a) Make a test program and run it with your above code to ensure you can read it properly. For example:

    public static void main(String[] args) {
      for(;;) {
        try {
          Thread.sleep(5000);
          System.out.println("Test output");
        } catch(InterruptedException e) {
          // Ignore
        }
    
      }
    }
    

    b) Make sure you are handling the process’ error stream – the process can lock up if you do not handle the error stream. Look at this site for a tutorial on the things to avoid while using Java’s ProcessBuilder or Runtime.exec() – it includes an implementation of a StreamGobbler that will throw away all data on a stream you don’t care about.

    c) Try using System.out.flush() – it may be that your output is being buffered.

    EDIT: Thanks for the update. Your problem is here:

    System.out.println(process.waitFor()); // Waits for the process to exit.
    while ((line = processReader.readLine()) != null) {
        System.out.println(line);
    }
    

    If you remove the waitFor() it will keep printing until the stream closes. The stream should only close if the process dies. You should put the waitFor() after the loop?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get output files from very old Fortran programs, which look like: 0.81667E+00 -0.12650E+01
I want to get output like 0 1 , but the code below just
I want to get output two bulleted lists like on the picture: But what
How can I get output from Java anonymous classes? In .Net I would use
My web host has a process killer which terminates any process running longer than
Consider the below String String names = Bharath-Vinayak-Harish-Punith I want to get output in
For example, how do I get Output.map from F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map
I get different output when mocking a class once and when mocking a class
How can you get unbuffered output from cout, so that it instantly writes to
I am able to get the output of a pdf using fpdf, the problem

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.