redirecting output from an unmanaged console application
-
Hi guys, i'm executing a console application using :
Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit();
i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik. -
Hi guys, i'm executing a console application using :
Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit();
i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik..... System.Diagnostics.Process pr = new System.Diagnostics.Process(); pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; pr.StartInfo.FileName = "cmd.exe"; pr.StartInfo.UseShellExecute = false; pr.StartInfo.RedirectStandardInput = true; pr.StartInfo.RedirectStandardOutput = true; pr.Start(); pr.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(pr_OutputDataReceived); pr.BeginOutputReadLine(); System.IO.StreamWriter swWriter = pr.StandardInput; swWriter.WriteLine("echo SomeTextHere\n"); swWriter.Flush(); .... void pr_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e) { MessageBox.Show(e.Data); }
UMS
-
Hi guys, i'm executing a console application using :
Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit();
i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik.