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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:32:56+00:00 2026-05-24T20:32:56+00:00

I am writing a C# winform application that starts a second process to execute

  • 0

I am writing a C# winform application that starts a second process to execute shell commands like “dir” and “ping”. I redirect the second process’s output so my app can receive the command result. It roughly works fine.

The only problem is my winform app receives the command line output as a whole instead of line by line. For example, it has to wait for the external “ping” command to finish (which takes many seconds or longer) and then receives the whole output (many lines) at once.

What I want is the app receives the cmdline output in real-time, i.e. by lines not by block. Is this doable?

I am using this code to read the output:
while ((result = proc.StandardOutput.ReadLine()) != null)

But it does not work the way I expected.
Thanks in advance.

EDIT: here is the code I am using:

    System.Diagnostics.ProcessStartInfo procStartInfo = new 
            System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

    procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

    // The following commands are needed to redirect the standard output.
    procStartInfo.RedirectStandardOutput = true;
    procStartInfo.UseShellExecute = false;
    procStartInfo.CreateNoWindow = true;
    // Now we create a process, assign its ProcessStartInfo and start it
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    proc.Start();

    // Get the output into a string
    string result;
    try {
        while ((result = proc.StandardOutput.ReadLine()) != null)
        {
            AppendRtfText(result+"\n", Brushes.Black);
        }
    } // here I expect it to update the text box line by line in real time
      // but it does not.
  • 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-24T20:32:58+00:00Added an answer on May 24, 2026 at 8:32 pm

    Have a look at the example in this msdn article on how to do the reading completly async.

    Beyond that I expect your code does to read line by line now but the UI doesn’t get any time to repaint (missing Application.DoEvents(); after updating the RTFTextBox

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

Sidebar

Related Questions

I'm writing an application that can be started either as a standard WinForms app
I'm writing a simple control in C# that works like a picture box, except
I'm writing an application in WinForms c# that is over 90k lines big. I
I'm interessted in writing an application that is running on windows mobile. I've allready
We're writing a .NET winform application and I'm looking for options on one of
I have written a winform application that connects to a database on our corporate
On a WinForms application that I am writing in C#, I have a DataGridViewTextBoxColumn
I am writing silverlight 3 application which is working on network. It works like
I am writing an application that will display serial/USB data at a rate of
I'm writing a program in WPF application that simulates the game of life. How

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.