From e19a2e2c403ac45fb5eab6c06dbe5108f8b6e542 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Sun, 24 Apr 2016 16:04:46 -0400 Subject: [PATCH] [Process] Fix System.Diagnostics.ProcessTest.StandardInputWrite The child process would simpky execute ls, then exiting right away. Writing to its stdin would then crash with "EPIPE: An attempt is made to write to a pipe that is not open for reading by any process." as the child process exited. --- .../Test/System.Diagnostics/ProcessTest.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs b/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs index f53d254c84417..75c4614ad2a43 100644 --- a/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs +++ b/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs @@ -881,6 +881,20 @@ ProcessStartInfo GetCrossPlatformStartInfo () } else return new ProcessStartInfo ("help", ""); } + + ProcessStartInfo GetEchoCrossPlatformStartInfo () + { + if (RunningOnUnix) { + string path; +#if MONODROID + path = "/system/bin/cat"; +#else + path = "/bin/cat"; +#endif + return new ProcessStartInfo (path); + } else + return new ProcessStartInfo ("type"); + } #endif // MONO_FEATURE_PROCESS_START [Test] @@ -972,14 +986,25 @@ public void DisposeWithDisposedStreams () [NUnit.Framework.Category ("MobileNotWorking")] public void StandardInputWrite () { - var psi = GetCrossPlatformStartInfo (); + var psi = GetEchoCrossPlatformStartInfo (); psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.UseShellExecute = false; using (var p = Process.Start (psi)) { - for (int i = 0; i < 1024 * 9; ++i) + // drain stdout + p.OutputDataReceived += (s, e) => {}; + p.BeginOutputReadLine (); + + for (int i = 0; i < 1024 * 9; ++i) { p.StandardInput.Write ('x'); + if (i > 0 && i % 128 == 0) + p.StandardInput.WriteLine (); + } + + p.StandardInput.Close (); + + p.WaitForExit (); } } #endif // MONO_FEATURE_PROCESS_START