コード例 #1
0
ファイル: Command.cs プロジェクト: isabella232/dotnet-do
        public Command(CommandSpec spec, ICommandExecutor executor)
        {
            _spec     = spec;
            _executor = executor;

            StartInfo          = new ProcessStartInfo();
            StartInfo.FileName = spec.Command;

            // Naive argument escaping
            StartInfo.Arguments = spec.EscapedArguments;
        }
コード例 #2
0
        public CommandResult Execute(CommandSpec spec, ProcessStartInfo startInfo, bool expectFailure)
        {
            var p = new Process();

            p.StartInfo = startInfo;

            StringBuilder stdout = new StringBuilder();

            if (p.StartInfo.RedirectStandardOutput)
            {
                p.OutputDataReceived += (sender, args) => stdout.AppendLine(args.Data);
            }

            StringBuilder stderr = new StringBuilder();

            if (p.StartInfo.RedirectStandardError)
            {
                p.ErrorDataReceived += (sender, args) => stderr.AppendLine(args.Data);
            }

            using (var activity = _log.BeginActivity("EXEC", FormatStartInfo(p.StartInfo)))
            {
                p.Start();

                if (p.StartInfo.RedirectStandardOutput)
                {
                    p.BeginOutputReadLine();
                }

                if (p.StartInfo.RedirectStandardError)
                {
                    p.BeginErrorReadLine();
                }

                p.WaitForExit();

                activity.Success    = (!expectFailure && p.ExitCode == 0) || (expectFailure && p.ExitCode == 0);
                activity.Conclusion = FormatConclusion(p.ExitCode, activity.Success);

                return(new CommandResult(spec, p.ExitCode, stdout.ToString(), stderr.ToString()));
            }
        }
コード例 #3
0
 public CommandResult(CommandSpec command, int exitCode, string stdout, string stderr) : this()
 {
     ExitCode = exitCode;
     StdOut   = stdout;
     StdErr   = stderr;
 }