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 9272549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:53:58+00:00 2026-06-18T15:53:58+00:00

I am trying to use common-exe asynchronous way to run the batch process from

  • 0

I am trying to use common-exe asynchronous way to run the batch process from java program, so that I can read and process the output stream from the batch process at runtime only.

I have learned that this piece of code runs the process asynchronously

DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
CommandLine cmdLine = new CommandLine("some batch file"); 
Executor executor = new DefaultExecutor(); 
executor.execute(cmdLine, resultHandler);

But now my problem is how read the out stream from the batch file parallelly to the execution. I have to process some information from the output stream.

Here is my piece of code from which I am trying.. I am not able to figure how to resolve my problem..

String command = "some batch file.bat";
PipedOutputStream pipedOutputStream = new PipedOutputStream();
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(pipedOutputStream);
CommandLine commandLine = null;

DefaultExecutor defaultExecutor = new DefaultExecutor();
DataInputStream dataInputStream = null;
DefaultExecuteResultHandler executeResultHandler = new DefaultExecuteResultHandler();

commandLine.parse(command);

try {
    dataInputStream = new DataInputStream(new PipedInputStream(pipedOutputStream));
    defaultExecutor.setStreamHandler(pumpStreamHandler);
    defaultExecutor.execute(commandLine, executeResultHandler);

    InputStream outCmdStream = null;
    pumpStreamHandler.setProcessOutputStream(outCmdStream);
    InputStreamReader outCmdReader = new InputStreamReader(outCmdStream);
    BufferedReader outCmdBufReader = new BufferedReader(outCmdReader);
    String procOutputStr;
    while ((procOutputStr = dataInputStream.readLine()) != null) {
        System.out.println(procOutputStr);
    }
} catch (IOException e) {
    e.printStackTrace();
    System.out.println("ERROR.RUNNING.CMD");
    e.printStackTrace();
    System.out.println("ERROR.RUNNING.CMD");
}
  • 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-06-18T15:53:59+00:00Added an answer on June 18, 2026 at 3:53 pm

    I have attained this feature with the help of SwingWorker abstract class.
    This abstract class provides several API to override, those can be used to perform the task in background.

    Following example shows how to execute background thread using swingworker.

        private Document doc;
     ...
     SwingWorker<Document, Void> worker = new SwingWorker<Document, Void>() {
       @Override
       public Document doInBackground() {
          // any action you want to perform in backgroud
          // i.e. in separate thread
       }
       @Override
       public void done() {
         try {
            // called after background thread is finished
         } catch (InterruptedException ex) {
           ex.printStackTrace();
         } catch (ExecutionException ex) {
           ex.printStackTrace();
         }
       }
     }
    

    Here are the links for the documentations and tutorials
    http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html
    http://en.wikipedia.org/wiki/SwingWorker

    Enjoy…

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

Sidebar

Related Questions

I am trying to use an external program from within Scala that accepts its
I'm currently trying to run MSTest.exe from NCover, but I believe the question could
I am trying to use a common technique to create objects from Xml. (Xml
I'm trying to use create a Clojure seq from some iterative Java library code
I am trying to use this tutorial from MS to verify I can build
I am trying to call MSTest.exe from a simple console app that is executed
I am trying to use the Base64 encoding functionality from Apache Common. But I
I'm trying to replace the programs that run from my startup directory with a
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.

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.