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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:29:35+00:00 2026-06-10T19:29:35+00:00

I have been through the StreamGobbler and I understand the usage and the reason

  • 0

I have been through the StreamGobbler and I understand the usage and the reason on why it has been implemented. However the scenarios covered are only those wherein there could be an output from the command / handling errors.

I do not find any scenario wherein StreamGobbler is used to handle inputs. For example, in mailx , I have to specify the body of the email, which I have done in the following format

Process proc = Runtime.getRuntime().exec(cmd);
OutputStreamWriter osw = new OutputStreamWriter(proc.getOutputStream());
osw.write(mailBody);
osw.close();

How can this be handled through StreamGobbler, or it is not required to be handled through it?

  • 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-10T19:29:37+00:00Added an answer on June 10, 2026 at 7:29 pm

    Ideally, you would employ the StreamGobbler on your error stream (in a separate thread) if you are already expecting something on InputStream, to look into when the process.waitFor() returns a non-zero value to find out the error message. If you are not interested in the InputStream, then you can read the ErrorStream directly in your code, once you are done with giving your inputs to the command.

    Process proc = Runtime.getRuntime().exec(cmd)
    // Start a stream gobbler to read the error stream.
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream());
    errorGobbler.start();
    
    OutputStreamWriter osw = new OutputStreamWriter(proc.getOutputStream())
    osw.write(mailBody)
    osw.close();
    
    int exitStatus = proc.waitFor();
    if (0 != exitStatus) {
        /*
         * If you had not used a StreamGobbler to read the errorStream, you wouldn't have
         * had a chance to know what went wrong with this command execution.
         */
        LOG.warn("Error while sending email: " + errorGobbler.getContent());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been through every option to try to find a way to get
I have been through the Apple Developer guides and tutorials and I been through
I have been through numerous similar questions on this forum but my issue still
I have been browsing through Google for various explanations but I STILL couldn't figure
I have been looking through the source code for the Flash-based Google TV example
I have been pouring through documentation as part of my quarter long project to
I have been reading through this wonderful website regarding the recommended Python IDEs and
I have been going through the core jQuery code and had a few why
I have been reading through the documentation on the JavaScriptMVC framework and it looks
I have been looking through code for the last 3 days, and the original

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.