none
c# process output redirection in realtime RRS feed

  • Question

  • I want to redirect process output on real time means whatever process does should be displayed on richtextbox

    Here is the piece of code  I am trying

    StringBuilder outputBuilder = new StringBuilder();

                ProcessStartInfo processStartInfo = new ProcessStartInfo();
                processStartInfo.CreateNoWindow = true;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardInput = true;
                processStartInfo.UseShellExecute = false;
                //processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                processStartInfo.WorkingDirectory = strHMIModelAppFolder;
                processStartInfo.FileName = ConfigurationHandlerInstance.GetHMIModelApplication();

                Process process = new Process();
                process.StartInfo = processStartInfo;
                process.EnableRaisingEvents = true;

                process.OutputDataReceived += new DataReceivedEventHandler
                (
                    delegate(object objSender, DataReceivedEventArgs eventArgs)
                    {
                        outputBuilder.Append(eventArgs.Data);
                        outputBuilder.Append(Environment.NewLine);
                        this.SetText(outputBuilder.ToString());
                    }
                );

                process.Exited += new EventHandler(ProcExited);
                process.Start();
                process.BeginOutputReadLine();

    • Edited by Swapnila Saturday, August 17, 2013 9:23 AM
    Saturday, August 17, 2013 7:37 AM

All replies

  • I want to redirect process output on real time means whatever process does should be displayed on richtextbox

    Here is the piece of code  I am trying

    StringBuilder outputBuilder = new StringBuilder();

                ProcessStartInfo processStartInfo = new ProcessStartInfo();
                processStartInfo.CreateNoWindow = true;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardInput = true;
                processStartInfo.UseShellExecute = false;
                //processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                processStartInfo.WorkingDirectory = strHMIModelAppFolder;
                processStartInfo.FileName = ConfigurationHandlerInstance.GetHMIModelApplication();

                Process process = new Process();
                process.StartInfo = processStartInfo;
                process.EnableRaisingEvents = true;

                process.OutputDataReceived += new DataReceivedEventHandler
                (
                    delegate(object objSender, DataReceivedEventArgs eventArgs)
                    {
                        outputBuilder.Append(eventArgs.Data);
                        outputBuilder.Append(Environment.NewLine);
                        this.SetText(outputBuilder.ToString());
                    }
                );

                process.Exited += new EventHandler(ProcExited);
                process.Start();
                process.BeginOutputReadLine();

    I am not able to redirect the output of process to richtextbox in realtime.
    Saturday, August 17, 2013 9:24 AM
  • Try the CSConsole project on my SkyDrive.



    • Edited by JohnWein Saturday, August 17, 2013 9:36 AM
    Saturday, August 17, 2013 9:34 AM