public static void Test_SubProcess_utf8()
        {
            // output
            string     ourEncWebName    = Console.OutputEncoding.WebName;
            string     waterTrebbleClef = "水𝄞";
            SubProcess sp = new SubProcess(echoArgs, "--utf8", waterTrebbleClef);

            sp.Wait();
            Assert.AreEqual(_(waterTrebbleClef + "\n"), sp.OutputString);
            Encoding ourEnc = Console.OutputEncoding;

            Assert.AreEqual(ourEnc.WebName, ourEncWebName);
            // has not changed to UTF-8
            Assert.AreNotEqual("utf-8", ourEnc.WebName);

            // error
            sp = new SubProcess(echoArgs, "--utf8", "--error", waterTrebbleClef);
            sp.Wait();
            Assert.AreEqual(_(waterTrebbleClef + "\n"), sp.ErrorString);

            // input
            //sp = new SubProcess(echoArgs, "--utf8", "--input-code-units", "--wait", "9999")
            sp = new SubProcess(echoArgs, "--utf8", "--input");
            sp.Start();
            sp.WriteLine(waterTrebbleClef);
            sp.Wait();
            Assert.AreEqual(_(waterTrebbleClef + "\n"), sp.OutputString);
        }
        public static void Test_SubProcess_outputPipe_OutputReader()
        {
            using (SubProcess sp = new SubProcess(echoArgs, "--input", "--input", "--input")
            {
                Out = SubProcess.Pipe
            })
            {
                // OutputReader
                sp.Start();
                string line = "hello subprocess";
                sp.WriteLine(line);
                Assert.AreEqual(line.ToUpper(), sp.OutputReader.ReadLine());

                string line2 = "some more text";
                sp.WriteLine(line2);
                Assert.AreEqual(line2.ToUpper(), sp.OutputReader.ReadLine());
            }
        }
        public static void Test_SubProcess_outputPipe_OutputStream()
        {
            using (SubProcess sp = new SubProcess(echoArgs, "--input", "--input", "--input")
            {
                Out = SubProcess.Pipe
            })
            {
                sp.Start();

                // OutputStream
                string line = "talking to subprocess";
                sp.WriteLine(line);
                MemoryStream ms = new MemoryStream();
                StreamWriter sw = new StreamWriter(ms);
                sw.WriteLine(line.ToUpper());
                sw.Flush();
                byte[] bytesRaw = ms.GetBuffer();
                byte[] bytes    = new byte[ms.Length];
                Array.Copy(bytesRaw, bytes, ms.Length);
                byte[] buffer = new byte[ms.Length];
                sp.OutputStream.Read(buffer, 0, (int)ms.Length);
                ms = new MemoryStream(buffer);
                string str = new StreamReader(ms).ReadToEnd();
                Assert.IsTrue(bytes.SequenceEqual(buffer));

                string line2 = "more interaction";
                sp.WriteLine(line2);
                ms = new MemoryStream();
                sw = new StreamWriter(ms);
                sw.WriteLine(line2.ToUpper());
                sw.Flush();
                bytesRaw = ms.GetBuffer();
                bytes    = new byte[ms.Length];
                Array.Copy(bytesRaw, bytes, ms.Length);
                buffer = new byte[ms.Length];
                sp.OutputStream.Read(buffer, 0, (int)ms.Length);
                Assert.IsTrue(bytes.SequenceEqual(buffer));
            }
        }
        public static void Test_SubProcess_input_pipe_writeline()
        {
            string line = "some input";

            SubProcess sp = new SubProcess(echoArgs, "--input")
            {
                In = SubProcess.Pipe
            };

            sp.Start();
            sp.WriteLine(line);
            sp.Wait();
            Assert.AreEqual(_(line.ToUpper() + "\n"), sp.OutputString);
        }
        public static void Test_SubProcess_nonUtf8()
        {
            Process p = new Process
            {
                StartInfo =
                {
                    FileName               = echoArgs,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardInput  = true,
                    CreateNoWindow         = true
                }
            };

            p.Start();
            Encoding enc = p.StandardOutput.CurrentEncoding;

            // Windows-1252
            // but SubProcess is actually IBM-850 (capitalises ä to å (in windows-1252) which
            // is õ to Õ in IBM-850)

            enc = Encoding.GetEncoding(850);

            string     line  = "a line ä";
            string     line2 = "a line Ë";
            SubProcess sp    = new SubProcess(echoArgs, "--input", "--error", line2)
            {
                OutEncoding   = enc,
                InEncoding    = enc,
                ErrorEncoding = enc
            };

            sp.Start();
            sp.WriteLine(line);
            sp.Wait();
            Assert.AreEqual(_(line.ToUpper() + "\n"), sp.OutputString);
            Assert.AreEqual(_(line2 + "\n"), sp.ErrorString);
        }