Example #1
0
        private CommandResult RunProcess(string executable, string args, StreamForwarder stdOut, StreamForwarder stdErr)
        {
            var psi = new ProcessStartInfo
            {
                FileName               = executable,
                Arguments              = args,
                RedirectStandardError  = true,
                RedirectStandardOutput = true
            };

            var process = new Process
            {
                StartInfo = psi
            };

            process.EnableRaisingEvents = true;
            process.Start();

            var threadOut = stdOut.BeginRead(process.StandardOutput);
            var threadErr = stdErr.BeginRead(process.StandardError);

            process.WaitForExit();
            threadOut.Join();
            threadErr.Join();

            var result = new CommandResult(
                process.StartInfo,
                process.ExitCode,
                stdOut.GetCapturedOutput(),
                stdErr.GetCapturedOutput());

            return(result);
        }
Example #2
0
File: E2ETest.cs Project: genlu/cli
    private static void Forward(int bufferSize, ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites)
    {
        var forwarder = new StreamForwarder(bufferSize);
        var writes    = new List <string>();

        if ((options & ForwardOptions.WriteLine) != 0)
        {
            forwarder.ForwardTo(
                write: (options & ForwardOptions.Write) == 0 ? (Action <string>)null : writes.Add,
                writeLine: s => writes.Add(s + "\n"));
        }
        if ((options & ForwardOptions.Capture) != 0)
        {
            forwarder.Capture();
        }
        forwarder.Read(new StringReader(str));
        Assert.Equal(expectedWrites, writes);
        var captured = forwarder.GetCapturedOutput();

        Assert.Equal(expectedCaptured, captured);
    }