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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:38:51+00:00 2026-05-16T03:38:51+00:00

I have a string that I need to pipe into an external program, then

  • 0

I have a string that I need to pipe into an external program, then read the output back. I understand how to read the output back, but how do I pipe this string as input? Thanks!

  • 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-16T03:38:51+00:00Added an answer on May 16, 2026 at 3:38 am

    Careful that you don’t create a deadlock. Reading/writing to the process in the same thread can be problematic if the process is writing data you are not reading and meanwhile you are writing data it is not reading.

    I tend to use a little pattern line this to get the io going in different threads:

    import java.io.InputStream;
    import java.io.OutputStream;
    
    public final class Pipe implements Runnable {
    
        private final InputStream in;
        private final OutputStream out;
    
        public Pipe(InputStream in, OutputStream out) {
            this.in = in;
            this.out = out;
        }
    
        public static void pipe(Process process) {
            pipe(process.getInputStream(), System.out);
            pipe(process.getErrorStream(), System.err);
            pipe(System.in, process.getOutputStream());
        }
    
        public static void pipe(InputStream in, OutputStream out) {
            final Thread thread = new Thread(new Pipe(in, out));
            thread.setDaemon(true);
            thread.start();
        }
    
        public void run() {
            try {
                int i = -1;
    
                byte[] buf = new byte[1024];
    
                while ((i = in.read(buf)) != -1) {
                    out.write(buf, 0, i);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    This may or may not apply to what you want to do — maybe your dealing with an established set of input that is guaranteed to show up after certain expected output (or vice versa, or several iterations of that). I.e. some synchronous block and step kind of interaction.

    But if you are simply ‘watching’ for something that might show up then this is a good start in the right direction. You would pass in some different streams and work in some java.util.concurrent ‘await(long,TimeUnit)’ type code for waiting for the response. Java IO blocks basically forever on read() ops, so separating yourself from those threads will allow you to give up after a certain time if you don’t get the expected response from the external process.

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer var nums = new int?[] {1, null, 3}; var total… May 16, 2026 at 12:43 pm
  • Editorial Team
    Editorial Team added an answer <style type="text/css"> .clear{ clear: both; } .top{ width: 100%; }… May 16, 2026 at 12:43 pm
  • Editorial Team
    Editorial Team added an answer Their algorithms aren't officially released to the public, but if… May 16, 2026 at 12:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have need to grep an entire directory for a string, and I get
I have a string that stores some variables that must be executed to produce
I have string. There are no items to show in this view of the
I have a regex issue that I need help with. Its trying to validate
I have code written that converts my Document to a string prior to printing
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
For example i have this string: $test_str = num Test \n num Hello \n
I am doing something that is probably silly, but it would be nice if
I am fairly new to scala and I have the need to convert a
I have a string buffer: b = create_string_buffer(numb) where numb is a number of

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.