コード例 #1
0
        /// <inheritdoc />
        public override bool ExecuteTask()
        {
            var proc = ProcessEx.CreateBackgroundProcess(Executable, Arguments, WorkingDirectory);

            ExitCode = proc.ExecuteBlockingWithOutputs(out var output, out var stdOutput, out var errOutput, out var timedOut, ProcessTimeOut);

            AllOutput      = output;
            StandardOutput = stdOutput;
            ErrorOutput    = errOutput;
            TimedOut       = timedOut;

            return(!FailOnNonZeroExitCode || ExitCode == 0);
        }
コード例 #2
0
        public static (bool success, string output) Execute(List <string> fullCmd, int timeout)
        {
            var bin  = fullCmd[0];
            var args = fullCmd.Skip(1).Select(GetPlaceholderValue);

            var p = ProcessEx.CreateBackgroundProcess(bin,
                                                      string.Join(" ",
                                                                  args),
                                                      Path.GetTempPath());

            var(exitCode, output, timedOut) = p.ExecuteBlockingWithOutputs(300000);

            return(timedOut == false && exitCode == 0, output);
        }
コード例 #3
0
        public static (bool success, string output) Execute(List <string> fullCmd, int timeout)
        {
            var bin     = fullCmd[0];
            var args    = fullCmd.Skip(1).Select(cmd => GetPlaceholderValue(cmd).Quotify()).ToList();
            var argsStr = string.Join(" ", args);

            LogTo.Debug($"Executing: {bin} {argsStr}.");

            var p = ProcessEx.CreateBackgroundProcess(bin, argsStr, Path.GetTempPath());

            var(exitCode, output, timedOut) = p.ExecuteBlockingWithOutputs(300000);

            LogTo.Debug($"Execution result:\r\nExit code: {exitCode}\r\nTimeout?: {timedOut}\r\nOutput:\r\n\r\n-------------------------------------------------\r\n{output}\r\n-------------------------------------------------\r\n");

            return(timedOut == false && exitCode == 0, output);
        }
コード例 #4
0
        public string ExecuteGit(string args,
                                 string exMsg = "An error occured while executing git command '{0}'.\nOutput: {1}",
                                 bool exFatal = true,
                                 bool throwOnNonZeroExitCode = true)
        {
            int    exitCode  = -2;
            string allOutput = string.Empty;
            bool   timedOut  = false;

            try
            {
                var gitFetch = ProcessEx.CreateBackgroundProcess(GitExecutable, args, WorkingDirectory);
                exitCode = gitFetch.ExecuteBlockingWithOutputs(
                    out allOutput,
                    out string stdOutput,
                    out _,
                    out timedOut,
                    ProcessTimeOut);

                TimedOut = timedOut;

                if (throwOnNonZeroExitCode && exitCode != 0)
                {
                    var gitCmd = $"{GitExecutable} \"{args}\"";

                    throw new ToolsException(string.Format(exMsg, gitCmd, allOutput), exFatal);
                }

                return(stdOutput);
            }
            finally
            {
                if (GitDebug)
                {
                    LogInfo($"Ran command: '{GitExecutable} {args}'. Timed out ? {timedOut}. Exit code {exitCode}. Output:\n{allOutput}");
                }
            }
        }