using System; using System.Threading; using System.Diagnostics; namespace TestPerlStdout { class Program { private static Process process; private static void ProcessStdout() { int totalBytes = 0; while (process.StandardOutput.Peek() >= 0) { char[] buffer = new char[4096]; int count = process.StandardOutput.Read(buffer, 0, buffer.Length); totalBytes += count; } Console.WriteLine(String.Format("Stopped processing after {0} bytes", totalBytes)); } static void Main(string[] args) { ProcessStartInfo si = new ProcessStartInfo(); si.FileName = "c:\\perl\\bin\\perl.exe"; si.Arguments = "-ne \"print qq($_\n)\" "; si.UseShellExecute = false; si.RedirectStandardOutput = true; si.RedirectStandardInput = true; process = Process.Start(si); ThreadStart start = new ThreadStart(ProcessStdout); Thread stdoutThread = new Thread(start); stdoutThread.Start(); while (true) { process.StandardInput.WriteLine("1"); process.StandardInput.Flush(); } } } }