bsdz has asked for the wisdom of the Perl Monks concerning the following question:
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(); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Connecting Perl's STDIN and STDOUT to .Net StreamReader
by Corion (Patriarch) on Sep 03, 2008 at 11:27 UTC | |
by bsdz (Friar) on Sep 03, 2008 at 11:45 UTC | |
by BrowserUk (Patriarch) on Sep 03, 2008 at 12:12 UTC | |
by bsdz (Friar) on Sep 03, 2008 at 13:23 UTC | |
|
Re: Connecting Perl's STDIN and STDOUT to .Net StreamReader
by moritz (Cardinal) on Sep 03, 2008 at 11:24 UTC |