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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:40:34+00:00 2026-05-22T02:40:34+00:00

I am reading the output of a java application started using Process and reading

  • 0

I am reading the output of a java application started using Process and reading stdError, stdOutout and using stdInput to send commands. Here is the relevant code:

        int mem = Properties.Settings.Default.mem_max;
        string locale = Properties.Settings.Default.location;
        Process bukkit_jva = new Process();
        bukkit_jva.StartInfo.FileName = "java";
        //bukkit_jva.StartInfo.Arguments = "-Xmx" + mem + "M -Xms" + mem + "M -jar " + locale + "bukkit.jar";
        bukkit_jva.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\bukkit\\bukkit.jar";
        bukkit_jva.StartInfo.UseShellExecute = false;
        bukkit_jva.StartInfo.CreateNoWindow = true;
        bukkit_jva.StartInfo.RedirectStandardError = true;
        bukkit_jva.StartInfo.RedirectStandardOutput = true;
        bukkit_jva.StartInfo.RedirectStandardInput = true;
        bukkit_jva.Start();
        //start reading output
        SetText(bukkit_jva.StandardOutput.ReadLine());
        SetText(bukkit_jva.StandardOutput.ReadLine());
        SetText(bukkit_jva.StandardOutput.ReadLine());
        SetText(bukkit_jva.StandardOutput.ReadLine());
        StreamReader err = bukkit_jva.StandardError;
        StreamReader output = bukkit_jva.StandardOutput;
        StreamWriter writer = bukkit_jva.StandardInput;
        SetText(err.Peek().ToString());
        while (false == false)
        {
            if (vars.input != null)
            {
                writer.WriteLine(vars.input);
                vars.input = null;
            }
            SetText(output.ReadLine() + err.ReadLine());
        }
    }

SetText() adds the line to a list of lines.

My problem is that the java app sometimes returns a string even when there is no input, so I always need to check for a new line. but If I need to send a command, and there is no new output, It will not send.

I tried different If statements on the readline, but it would only return the first few lines then it would stop.

basicly it seems to pause the loop if there is no new line for it to read.

How could I either setup my read/write loop differently or get the loop to unpause?

Thanks,
Adam

  • 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-22T02:40:34+00:00Added an answer on May 22, 2026 at 2:40 am

    try this:

    static void Main(string[] args)
    {
        ProcessStartInfo psi = new ProcessStartInfo("echoApp.exe");
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.UseShellExecute = false;
    
        Process echoApp = new Process();
        echoApp.ErrorDataReceived += new DataReceivedEventHandler(echoApp_ErrorDataReceived);
        echoApp.OutputDataReceived += new DataReceivedEventHandler(echoApp_OutputDataReceived);
        echoApp.StartInfo = psi;
        echoApp.Start();
        echoApp.BeginOutputReadLine();
        echoApp.BeginErrorReadLine();
        echoApp.StandardInput.AutoFlush = true;
    
        string str = "";
        while (str != "end")
        {
            str = Console.ReadLine();
            echoApp.StandardInput.WriteLine(str);
        }
        echoApp.CancelOutputRead();
        echoApp.CancelErrorRead();
        echoApp.Close();
    }
    
    static void echoApp_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine("stdout: {0}", e.Data);
    }
    
    static void echoApp_ErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine("stderr: {0}", e.Data);
    }
    

    and the little echoApp…

    //echoApp
    static void Main(string[] args)
    {
        string str="";
        while (str != "end")
        {
            str = Console.ReadLine();
            Console.WriteLine(str);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using a java application to run commands on a unix box by
I was reading about output buffering in JavaScript here , and was trying to
I'm using java servlets and jsp in my application and I need to read
Creating this application has become a pain in the ass! Using Java I want
Reading this question I found this as (note the quotation marks) code to solve
Reading source code of sample projects, such as Beast and Bort, are recommended as
I am writing a Java application which can encrypt and consequently decrypt whatever binary
I have a swing Java application that preserves a lot of data (you can
I'm trying to make sure my Java application takes reasonable steps to be robust,
I'm using Eclipse to develop a java web app and My IT department called

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.