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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:46:18+00:00 2026-05-23T13:46:18+00:00

I have a small wrapping application to give a GUI to an existing console

  • 0

I have a small wrapping application to give a GUI to an existing console application. I’m using the ProcessStartInfo and Process class to bind to the .exe, and then using BeginErrorReadLine() and BeginOutputReadLine() to redirect any messages into the new GUI. Everything works fine except for when the console calls Console.Write() instead Console.WriteLine(), in which case the text passed to Write is not displayed at all. I would think that the problem is because the WriteLine function inserts a line break after the text, and the Write method does not. Is there any way to circumvent this? I can’t change it from Write to WriteLine in the original command line program as Write is used to prompt for input.

Relevant Code:

var startInfo = new ProcessStartInfo(ServerFile);
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;

ServerProc = new Process();
ServerProc.StartInfo = startInfo;
ServerProc.EnableRaisingEvents = true;
ServerProc.ErrorDataReceived += new DataReceivedEventHandler(ServerProc_ErrorDataReceived);
ServerProc.OutputDataReceived += new DataReceivedEventHandler(ServerProc_OutputDataReceived);

private void ServerProc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
    Dispatcher.Invoke(new Action(() =>
    {
        ConsoleTextBlock.Text += e.Data + "\r\n";
        ConsoleScroll.ScrollToEnd();
    }));
}

private void ServerProc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    Dispatcher.Invoke(new Action(() =>
    {
        ConsoleTextBlock.Text += e.Data + "\r\n";
        ConsoleScroll.ScrollToEnd();
    }));
}
  • 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-23T13:46:18+00:00Added an answer on May 23, 2026 at 1:46 pm

    The problem you are experiencing is that the Process class is set up for convenient line-oriented event-based processing of the output of the process. You cannot use this functionality if you need to read partial lines as they are being output.

    Nevertheless, the Process class does give you the tools you need if you need finer-grained control over the output than the line-oriented facilities. If you redirect the output, then Process.StandardOutput is a StreamReader and you have the whole StreamReader API that you can use instead of being forced to read entire lines.

    For example, here is a character-by-character read of the standard output:

    var start = DateTime.Now;
    int n;
    while ((n = ServerProc.StandardOutput.Read()) != -1)
    {
        var c = (char)n;
        var delta = (DateTime.Now - start).TotalMilliseconds;
        Console.WriteLine("c = {0} (0x{1:X}) delta = {2}",
            char.IsWhiteSpace(c) ? '*' : c, n, delta);
    }
    

    If we run it on another console program that produces this output:

    Console.Write("abc");
    Thread.Sleep(1000);
    Console.WriteLine("def");
    

    It produces this output:

    c = a (0x61) delta = 44.0025
    c = b (0x62) delta = 44.0025
    c = c (0x63) delta = 44.0025
    c = d (0x64) delta = 1109.0634
    c = e (0x65) delta = 1110.0635
    c = f (0x66) delta = 1110.0635
    c = * (0xD) delta = 1110.0635
    c = * (0xA) delta = 1110.0635
    

    which shows that the "abc" was read one second before the rest of the line.

    However, this is not convenient if you like the event-oriented I/O already provided by Process. You can either:

    • use the async Stream API
    • use threads that do blocking reads

    and perhaps even roll your own event-based I/O that meets your needs.

    You are writing a program that is parsing another program’s character-oriented output and so without full lines you will need some sort of timeout to indicate “I now satisfied that the program is done producing output for the time being.” This can be easy or hard depending on how predictable the output is. For example, you might be able to recognize a prompt that ends with a "?". It depends on your situation.

    The point is that you’ll have to use the StandardOutput and StandardError StreamReader properties if you want something other than line-oriented I/O.

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

Sidebar

Related Questions

I have a small VB.NET application that I'm working on using the full version
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small diagnostic VB.Net application ( 2 forms, 20 subs & functions)
I have a small application I am working on that at one point needs
For my small wiki application, I mostly need to have the textarea used to
I have small COCOA Mac OS application to play with core data. I have
I have small page which has label, DropDownList and a submit button. <div> <asp:label
Where I work, we have small teams of 2 - 5 people. As a
I have a small JS function that does Ajax for me and another like
I have a small utility that I use to download an MP3 file from

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.