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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:03:08+00:00 2026-05-30T05:03:08+00:00

How can I send and receive multiple inputs using Runtime.getRunTime.exec(). For example if I

  • 0

How can I send and receive multiple inputs using Runtime.getRunTime.exec().

For example if I wanted to run something such as openSSL to generate a csr, it will ask for things such as state, city, common name.. and so on.

Process p = Runtime.getRuntime().exec(cmd);
OutputStream out = p.getOutputStream();
//print stuff p.getInputStream(); 
//Now i want to send some inputs 
out.write("test".getBytes()); 
//flush and close??? don't know what to do here
//print what ever is returned
//Now i want to send some more inputs 
out.write("test2".getBytes());
//print what ever is returned.. and so on until this is complete

why not use p.getInputStream() to read what you need to send while
using out.write() to send data accordingly.

Process p = Runtime.getRuntime().exec(cmd);
OutputStream out = p.getOutputStream();
//print stuff p.getInputStream();
out.write("test".getBytes()); 
out.close(); //if i don't close, it will just sit there 
//print stuff p.getInputStream();
out.write("test".getBytes()); // I can no longer write at this point, maybe because the outputstream was closed? 
  • 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-30T05:03:09+00:00Added an answer on May 30, 2026 at 5:03 am

    why not use p.getInputStream().read() to read what you need to send while using out.write() to send data accordingly.

    here is an example taken from: http://www.rgagnon.com/javadetails/java-0014.html

    String line;
    OutputStream stdin = null;
    InputStream stderr = null;
    InputStream stdout = null;
    
      // launch EXE and grab stdin/stdout and stderr
      Process process = Runtime.getRuntime ().exec ("/folder/exec.exe");
      stdin = process.getOutputStream ();
      stderr = process.getErrorStream ();
      stdout = process.getInputStream ();
    
      // "write" the parms into stdin
      line = "param1" + "\n";
      stdin.write(line.getBytes() );
      stdin.flush();
    
      line = "param2" + "\n";
      stdin.write(line.getBytes() );
      stdin.flush();
    
      line = "param3" + "\n";
      stdin.write(line.getBytes() );
      stdin.flush();
    
      stdin.close();
    
      // clean up if any output in stdout
      BufferedReader brCleanUp =
        new BufferedReader (new InputStreamReader (stdout));
      while ((line = brCleanUp.readLine ()) != null) {
        //System.out.println ("[Stdout] " + line);
      }
      brCleanUp.close();
    
      // clean up if any output in stderr
      brCleanUp =
        new BufferedReader (new InputStreamReader (stderr));
      while ((line = brCleanUp.readLine ()) != null) {
        //System.out.println ("[Stderr] " + line);
      }
      brCleanUp.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i send and receive data though parallel port using C# .net? Also
Using cURL I can send a GET request with a body. Example: curl -i
I am making a messaging application in which user can send or receive a
I can send requests to friends using Multi Friend Request Selector inside my Page
Is there any way I can send an email, like any frameworks or something.
How to send HTML content in email using Python? I can send simple texts.
Why can't I send emails to multiple recipients with this script? I get no
I am looking into designing an application that can run on multiple platforms (i.e.
how can i send multiple files over TCP with C#, all the samples on
In Javascript I can send XML string to JSP server (XmlAction.jsp): Javascript Code: var

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.