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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:15:28+00:00 2026-05-22T16:15:28+00:00

I am trying to call a simple program test.exe which is as simple as-

  • 0

I am trying to call a simple program test.exe which is as simple as-

int main()
{
    int a;
    cout<<"Welcome\n";
    while(cin>>a&&a!=0)
    cout<<"you entered "<<a<<endl;
}

I want to run it from a java program as a process, and send+recieve i/o from it. I am using the process with 2 threads as follows-

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

public class Processproblem {

    public static void main(String[] args)throws IOException, InterruptedException {
        final Process process;
          try {
            process = Runtime.getRuntime().exec("test.exe");
        } catch (IOException e1) {
            e1.printStackTrace();
            return;
        }

           new Thread(new Runnable() {
            public void run() {
                String line;
                BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
                try {
                    while ((line = br.readLine()) != null) {
                        System.out.println("[OUT] " + line);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();


      new Thread(new Runnable() {
        public void run() {
            try {
                byte[] buffer = new byte[1024];
                int reading=0;
                System.out.println(reading);
                BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

                while(reading!=-1)
                {
                     reading= System.in.read(buffer);
                     for(int i = 0; i < buffer.length; i++) {
                        int intValue = new Byte(buffer[i]).intValue();
                        if (intValue == 0) {
                            reading = i;
                            break;
                        }
                        else
                        {
                            bw.append((char)intValue);
                        }
                    }
                      bw.newLine();
                        bw.flush();

                }

            } catch (Exception e) {
            }
        }
    }
            ).start();
    }
}

But they are not working as expected. When i run the program it just shows the “Welcome\n” message and then stops for input. When i give a integer and press enter in the java console it does nothing.

What am I doing wrong? They are two separate threads so why are they blocking each other? Is there any problem in my concept?

  • 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-22T16:15:28+00:00Added an answer on May 22, 2026 at 4:15 pm

    The program waits for your input. Grab the process output stream (using getOutputStream) and write to it.

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

Sidebar

Related Questions

I'm trying to write a simple program which uses libcurl to perform HTTP POST
I've simple program e.g. in C++ #include <iostream> int main() { int a =
I am trying to call MSTest.exe from a simple console app that is executed
I'm trying to create a simple Java app that uses JNI to call some
I am trying to make a simple call to the pow() function from math.h
i'm trying to make a simple Java program to open an existing word-document, change
I'm trying to write a simple thread pool program in pthread. However, it seems
On Debian, I am trying to compile a CLISP program which uses the cl-ppcre
I trying to use OpenCL using HASKELL. I write a simple program converting a
I'm trying to create a very simple Hello, world program in RoR, but when

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.