I am starting a Perl process using C#'s Process class which redirects its STDIN and STDOUT to internal .Net StreamReader objects. The problem is that the Perl process appears to close its STDOUT prematurely even when it has more data to process. I am not sure if this is a .Net issue or a Perl issue. Here is my C# code: -
On running this, the console outputs "Stopped processing after 8191 bytes". Can anyone help me with some insight to what is happening?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.Leng +th); totalBytes += count; } Console.WriteLine(String.Format("Stopped processing after {0} by +tes", 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(); } } } }
In reply to Connecting Perl's STDIN and STDOUT to .Net StreamReader by bsdz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |