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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:30:09+00:00 2026-06-09T09:30:09+00:00

public static void executeCommand(String cmd) { try { Process process = Runtime.getRuntime().exec(cmd, null, new

  • 0
public static void executeCommand(String cmd) {
    try {
        Process process = Runtime.getRuntime().exec(cmd, null,
                new File("/usr/hadoop-0.20.2/"));
        InputStream stdin = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(stdin);
        BufferedReader br = new BufferedReader(isr);
        String line;
        System.out.println("<output></output>");
        while ((line = br.readLine()) != null)
            System.out.println(line);
        InputStreamReader esr = new InputStreamReader(
                process.getErrorStream());
        BufferedReader errorReader = new BufferedReader(esr);
        String lineError;
        while ((lineError = errorReader.readLine()) != null)
            System.out.println(lineError);
        process.waitFor();
        System.out.println("");

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

Here’s my code for executing a command named ‘cmd’. But I cannot get realtime output through this code. The output comes out when the command finishes. I want realtime output. Is there a way to do this?

  • 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-09T09:30:11+00:00Added an answer on June 9, 2026 at 9:30 am

    The issue you describe is most likely caused by the application you called: many applications use unbuffered I/O when connected to a terminal, but bufferen I/O when connected to a pipe. So your cmd may simply decide not to write its output in small bits, but instead in huge chunks. The proper fix is to adjust the command, to flush its output at the appropriate times. There is little you can do about this on the Java side. See also this answer.

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

Sidebar

Related Questions

public static void main(String args[]) throws IOException { Process p = Runtime.getRuntime().exec(java E:/workspace/JNIProgram/src/JNIProgram.class); }
public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);
public static void main(String[] args) { staples[] stemp = new staples[8]; int j; try
public static void WriteLine(string text) { StreamWriter log; if (!File.Exists(Filename)) { log = new
public static void parseProfilesJson(String the_json){ try { JSONObject myjson = new JSONObject(the_json); JSONArray nameArray
public static void getMembers(WebDriver driver, String outname){ FileWriter outFile = null; try { outFile
public static void Main() { Dictionary<string, double> values = new Dictionary<string, double>(); values.Add(a, 0.002);
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class MultiplicationTable { public static void main (String[]a){ int[] x; x = new
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat =

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.