Results 1 to 5 of 5

Thread: [RESOLVED] How to run a process and get its output continously?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    146

    Resolved [RESOLVED] How to run a process and get its output continously?

    consoletest.exe

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                int i;
    
                for (i = 0; i < 10000; i++)
                    Console.Out.WriteLine(i.ToString());
    
    
    
    
    
            }
        }
    }

    windows project

    Code:
     private void button1_Click(object sender, EventArgs e)
            {
                System.Windows.Forms.Application.DoEvents();
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo();
    
    
                pi.FileName = "C:\\consoletest.exe";
                pi.Arguments = "C:\\mailbox";
                pi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                pi.RedirectStandardOutput = true;
                pi.UseShellExecute = false;
    
                proc.StartInfo = pi;
                proc.Start();
                System.IO.StreamReader myOutput = proc.StandardOutput;
                           
    
    
                proc.WaitForExit();
                if (proc.HasExited)
                {
                    string output = myOutput.ReadToEnd();
                    textBox1.Text = output;
                }
            }
    The question is

    How do I run the console program in background and update its output in real time to the textbox?
    The windows program should also continue accepting other Events while the console process is being executed.
    Last edited by winterslam; Jul 12th, 2009 at 06:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width