Esempio n. 1
0
 public ICommand CaptureStdErr()
 {
     ThrowIfRunning();
     EnsureStdErr();
     _stdErr.Capture();
     return(this);
 }
Esempio n. 2
0
 public ICommand CaptureStdErr()
 {
     ThrowIfRunning();
     EnsureStdErr();
     _stdErr.Capture(_trimTrailingNewlines);
     return(this);
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 5
0
 public Command CaptureStdOut()
 {
     ThrowIfRunning();
     _stdOut.Capture();
     return(this);
 }
Esempio n. 6
0
 public ICommand CaptureStdOut()
 {
     _stdOut.Capture();
     return(this);
 }
Esempio n. 7
0
 public ICommand CaptureStdErr()
 {
     _stdErr.Capture();
     return(this);
 }
Esempio n. 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);
 }
Esempio n. 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);
        }