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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:58:23+00:00 2026-06-10T09:58:23+00:00

I am executing a simple jar file by using process builder. The jar file

  • 0

I am executing a simple jar file by using process builder. The jar file simply computes the square of a number by asking the user to enter a number. I can enter a number at console but the program hangs. How can I pass this (number) back to process builder for its square to be computed by the jar file?

Here is my code for this:

public static void executeSystemCommand(String... args) {
try {
    ProcessBuilder pb = new ProcessBuilder(args);

    pb.redirectErrorStream(true);           
    Process proc = pb.start();
    Reader reader = new InputStreamReader(proc.getInputStream());

    int ch;
    while ((ch = reader.read()) != -1) {
        System.out.print((char) ch);    
    }

    reader.close();
    Scanner scan = new Scanner(System.in);

    int k = scan.nextInt();
    proc.getOutputStream().write(k);
    proc.getOutputStream().close();

    while ((ch = reader.read()) != -1) {
        System.out.print((char) ch);    
    }

    reader.close();
} catch (IOException e) {
    e.printStackTrace();
    System.exit(-1);
}
}
  • 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-10T09:58:25+00:00Added an answer on June 10, 2026 at 9:58 am

    Here is a code that inputs a string b to the jar file and returns an arraylist of booleans on the basis of output received from the jar file.

    public ArrayList<Boolean> pro(String b) throws IOException, Exception {
            ArrayList<Boolean> ar = new ArrayList<Boolean>();
            try {
                ProcessBuilder pb = new ProcessBuilder("java", "-jar",
                        "myjar.jar");
    
                pb.directory(new File("path to myjar"));
                Process proc = pb.start();
    
                Scanner in = new Scanner(proc.getInputStream());
                PrintWriter out = new PrintWriter(proc.getOutputStream());
    
                // Read user input
                out.println(b);
                out.flush();
                String response = new String();
    
                // Read the response
                for (int i = 0; i < b.length(); i++)
                    response = in.nextLine();
    
                in.close();
                out.close();
    
                StringTokenizer st = new StringTokenizer(response);
                while (st.hasMoreTokens()) {
                    String bol = st.nextToken();
    
                    if (bol.equals("true"))
                        ar.add(true);
                    else
                        ar.add(false);
    
                }
    
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ar;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to load resource from my own executing JAR as
Is it possible to connect to Sql Server for the purpose of executing simple
My question is rather simple. Let's suppose I'm executing the algorithm A star (search
At a unix command line, what's the difference between executing a program by simply
I wanted to implement a simple python program using parallel execution. It's I/O bound,
After using the ebay API recently, I was expecting it to be as simple
I run a simple CXF maven project http://cxf.apache.org/docs/using-cxf-with-maven.html , and get error below [INFO]
I have a simple java maven project. One of my classes when executing needs
I have the following piece of code, executing a pretty simple MySQL query: $netnestquery
I have made a simple batch file for backing up my repository changes and

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.