Пример #1
0
 public ICommand CaptureStdErr()
 {
     ThrowIfRunning();
     EnsureStdErr();
     _stdErr.Capture();
     return(this);
 }
Пример #2
0
 public ICommand CaptureStdErr()
 {
     ThrowIfRunning();
     EnsureStdErr();
     _stdErr.Capture(_trimTrailingNewlines);
     return(this);
 }
Пример #3
0
        public virtual CommandResult ExecuteWithCapturedOutput(string args = "")
        {
            Console.WriteLine($"Executing (Captured Output) - {_command} {args}");

            var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
                Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");

            var stdOut = new StreamForwarder();
            var stdErr = new StreamForwarder();

            stdOut.Capture();
            stdErr.Capture();

            return RunProcess(commandPath, args, stdOut, stdErr);
        }
Пример #4
0
        public virtual CommandResult ExecuteWithCapturedOutput(string args = "")
        {
            var command = _command;
            ResolveCommand(ref command, ref args);
            var commandPath = Env.GetCommandPath(command, ".exe", ".cmd", "") ??
                Env.GetCommandPathFromRootPath(_baseDirectory, command, ".exe", ".cmd", "");

            Console.WriteLine($"Executing (Captured Output) - {commandPath} {args}");

            var stdOut = new StreamForwarder();
            var stdErr = new StreamForwarder();

            stdOut.Capture();
            stdErr.Capture();

            return RunProcess(commandPath, args, stdOut, stdErr);
        }
Пример #5
0
 public Command CaptureStdOut()
 {
     ThrowIfRunning();
     _stdOut.Capture();
     return(this);
 }
Пример #6
0
 public ICommand CaptureStdOut()
 {
     _stdOut.Capture();
     return(this);
 }
Пример #7
0
 public ICommand CaptureStdErr()
 {
     _stdErr.Capture();
     return(this);
 }
Пример #8
0
 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);
 }
Пример #9
0
        private void TestCapturingAndForwardingHelper(ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites)
        {
            var forwarder = new StreamForwarder();
            var writes = new List<string>();

            if ((options & ForwardOptions.WriteLine) != 0)
            {
                forwarder.ForwardTo(writeLine: s => writes.Add(s + Environment.NewLine));
            }
            if ((options & ForwardOptions.Capture) != 0)
            {
                forwarder.Capture();
            }

            forwarder.Read(new StringReader(str));
            Assert.Equal(expectedWrites, writes);

            var captured = forwarder.CapturedOutput;
            Assert.Equal(expectedCaptured, captured);
        }