Ejemplo n.º 1
0
        public virtual CommandResult Execute(params string[] args)
        {
            var commandPath = _command;

            ResolveCommand(ref commandPath);

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

            stdOut.ForwardTo(Log);
            stdErr.ForwardTo(Log);

            return(RunProcess(commandPath, args, stdOut, stdErr));
        }
Ejemplo n.º 2
0
        public virtual CommandResult Execute(string args = "")
        {
            var commandPath = _command;

            ResolveCommand(ref commandPath, ref args);

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

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

            stdOut.ForwardTo(writeLine: Reporter.Output.WriteLine);
            stdErr.ForwardTo(writeLine: Reporter.Output.WriteLine);

            return(RunProcess(commandPath, args, stdOut, stdErr));
        }
Ejemplo n.º 3
0
        public virtual CommandResult Execute(string args = "")
        {
            var commandPath = _command;

            ResolveCommand(ref commandPath, ref args);

            Log($"Executing - {commandPath} {args}");

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

            stdOut.ForwardTo(Log);
            stdErr.ForwardTo(Log);

            return(RunProcess(commandPath, args, stdOut, stdErr));
        }
Ejemplo n.º 4
0
        public virtual Task<CommandResult> ExecuteAsync(string args = "")
        {
            var commandPath = _command;
            ResolveCommand(ref commandPath, ref args);

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

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

            AddWriteLine(Reporter.Output.WriteLine);

            stdOut.ForwardTo(writeLine: WriteLine);
            stdErr.ForwardTo(writeLine: WriteLine);

            return RunProcessAsync(commandPath, args, stdOut, stdErr);
        }
Ejemplo n.º 5
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} - {WorkingDirectoryInfo()}");

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

            stdOut.ForwardTo(writeLine: WriteLine);
            stdErr.ForwardTo(writeLine: WriteLine);

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

            return RunProcess(commandPath, args, stdOut, stdErr);
        }
Ejemplo n.º 6
0
        public virtual CommandResult Execute(string args = "")
        {
            var commandPath = _command;

            if (!Path.IsPathRooted(_command))
            {
                _command = Env.GetCommandPath(_command) ??
                           Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command);
            }

            Console.WriteLine($"Executing - {_command} {args}");

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

            stdOut.ForwardTo(write: Reporter.Output.Write, writeLine: Reporter.Output.WriteLine);
            stdErr.ForwardTo(write: Reporter.Error.Write, writeLine: Reporter.Output.WriteLine);

            return(RunProcess(commandPath, args, stdOut, stdErr));
        }
Ejemplo n.º 7
0
Archivo: E2ETest.cs Proyecto: 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);
    }
Ejemplo n.º 8
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);
        }